外键如何设置
我建两个表
create table City
(
CityID int identity(1,1) primary key not null,
CityName varchar(20) not null,
DistrictCode varchar(4) not null,
)
create table Weather
(
WeatherId int identity(1,1) primary key not null,
WeatherDate dateTime not null,
CityID int foreign key not null,/*外键如何设置*/
Weather varchar(256) not null,
)
------解决方案--------------------CityID int foreign key references city(cityid) not null,/*外键如何设置*/
------解决方案-------------------- create table City
(
CityID int identity(1,1) primary key not null,
CityName varchar(20) not null,
DistrictCode varchar(4) not null,
)
create table Weather
(
WeatherId int identity(1,1) primary key not null,
WeatherDate dateTime not null,
CityID int foreign key not null,/*外键如何设置*/
Weather varchar(256) not null,
CONSTRAINT [FK_WEATHER_REFERENCE_CityID] FOREIGN KEY
(
[CityID]
) REFERENCES [City] (
[CityID ]
)
)