老司机深夜免费福利-老司机深夜影院入口aaaa-老司机午夜精品99久久免费-老司机午夜精品视频-老司机午夜精品视频播放-老司机午夜精品视频你懂的

SQL Server使用介紹(七)

今天我們將剩下的表都創建好,除了之前的AccpStudent,AccpClass表,還有AccpSubject(課程表),AccpScore(成績表),以及他們之間的引用關系.
首先創建AccpSubject表
create table AccpSubject
(
 sid int identity(1,1) primary key, --課程編號
 subName varchar(50) not null  --課程名稱
)
go

create table AccpScore
(
 sid int identity(1,1), --成績編號
 subId int not null, --課程Id
 stuId int not null, --學生Id
 Score int check(Score>=0 and Score<=100), --成績
)
go
然后再創建表和表之間的引用關系,這里有2個引用關系需要創建
第一,是AccpScore表和accpStudent之間的引用關系,創建引用關系代碼如下:
alter table AccoScore
add constrint FK_AccpScore_AccpStudent foreign key(stuId) references AccpStudent(sid)
go

第二,是AccpScore表和AccpSubject課程表之間的引用關系,創建引用關系代碼如下:
alter table AccoScore
add constrint FK_AccpScore_AccpSubject foreign key(subId) references AccpSubject(sid)
go
這樣到目前為止,所有的數據庫和表都創建好了。

北大青鳥網上報名
北大青鳥招生簡章