0

high guyz i have this simple problem but for a newbie like me its really hard this is my problem.

I need to create two tables with relation ship but it says that only one identity can use for each table or is there other way that i can copy all the data from other table with foreign key without typing the same data? your help will be appriciated thank you! :)

create table Students
(Student_no int Unique identity(4100490,1)
,Last_name nvarchar(30)
,First_name nvarchar(40)
,Birthday Date)

create table Schedule
(Schedule_ID int primary key identity(650500,1)
,Section nvarchar(10) Unique
,Subject_code nvarchar(10) foreign key references Subjects(Subject_code)
,Days nvarchar(10)
,Time time
,Room nvarchar(10))

create table Enlistment
(Enlistment_ID nvarchar(10)primary key 
,Student_No int foreign key references students(Student_no) identity(4100490,1)
,Schedule_ID int foreign key references Schedule(Schedule_ID) identity(650500,1))
4

1 回答 1

0

尝试这个:

create table Students
(Student_no integer PRIMARY KEY
,Last_name nvarchar(30)
,First_name nvarchar(40)
,Birthday Date)

create table Schedule
(Schedule_ID integer primary key
,Section nvarchar(10) Unique
,Subject_code nvarchar(10) foreign key references Subjects(Subject_code)
,Days nvarchar(10)
,Time time
,Room nvarchar(10))

create table Enlistment
(Enlistment_ID integer primary key -- this was nvarchar in your code.
    -- Use NVARCHAR in primary keys only if you absolutely need it.
    -- If you are storing only numbers in it, you won't need NVARCHAR.
    -- use INTEGER instead.
,Student_No int foreign key references students(Student_no) identity(4100490,1)
,Schedule_ID int foreign key references Schedule(Schedule_ID) identity(650500,1))
于 2013-03-17T17:30:24.800 回答