Create Table Movie (
ID int not null IDENTITY(1,1) Primary Key,
Title varchar(50),
ReleaseDate date not null,
Genre varchar(50),
Price decimal(18,2),
Rating varchar(50),
Autors_ID int FOREIGN KEY REFERENCES Movie_Autors(Autors_ID)
)
Create Table Autors (
ID int not null IDENTITY(1,1) Primary Key,
Name varchar(50),
Born date not null,
About text,
Movie_ID int FOREIGN KEY REFERENCES Movie_Autors(Movie_ID)
)
Create Table Movie_Autors (
ID int not null IDENTITY(1,1) Primary Key,
Movie_ID int FOREIGN KEY REFERENCES Movie(ID),
Autors_ID int FOREIGN KEY REFERENCES Autors(ID),
)
答案 0 :(得分:2)
大概是您想要的:
Create Table Movie (
ID int not null IDENTITY(1,1) Primary Key,
Title varchar(50),
ReleaseDate date not null,
Genre varchar(50),
Price decimal(18,2),
Rating varchar(50)
);
Create Table Autors (
ID int not null IDENTITY(1,1) Primary Key,
Name varchar(50),
Born date not null,
About varchar(max)
);
Create Table Movie_Autors (
ID int not null IDENTITY(1,1) Primary Key,
Movie_ID int FOREIGN KEY REFERENCES Movie(ID),
Autors_ID int FOREIGN KEY REFERENCES Autors(ID),
);
也就是说,您在Movies
或Autors
中没有外键引用,因此您不应声明任何外键引用。
请注意,NOT NULL
和PRIMARY KEY
是多余的。 PRIMARY KEY
就足够了。
我也将text
更改为varchar(max)
。 The text
datatype has been deprecated.