2013-03-17 39 views
0

高guyz我有這個簡單的問題,但對於像我這樣的新手它真的很難 這是我的問題。複製,身份,關係

我需要創建兩個表的關係,但它說,只有一個標識 可以用於每個表或有其他方式,我可以從外鍵複製其他表中的所有數據而無需鍵入相同的數據? 你的幫助將會感謝你! :)

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)) 
+2

我** **不高! – wildplasser 2013-03-17 17:08:20

回答

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))