我有两张表CAR
和CAR_BRAND
:
CREATE TABLE car
(
car_id int NOT NULL IDENTITY(1,1) PRIMARY KEY,
car_brand int NOT NULL,
tech_passport nvarchar(17) NOT NULL,
vin_code nvarchar(17) NOT NULL,
)
CREATE TABLE car_brand
(
car_brand_id int NOT NULL IDENTITY(1,1) PRIMARY KEY,
name_brand nvarchar(15),
country_brand nvarchar(20),
)
如何在这两个表之间建立一对一的关系?一辆车有一个品牌
答案 0 :(得分:2)
就像这样:
ALTER TABLE dbo.Car
ADD CONSTRAINT FK_Car_CarBrand
FOREIGN KEY (Car_Brand) REFERENCES dbo.Car_Brand(Car_Brand_id)