### 1、使用教材P48页上的SQL语句,在数据库sjkDB上创建教材的表3-3和表3-4所示的员工表和薪资表,使用SQL语句或SQL Server Management Studio完成教材例3-16~例3-24的操作。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| alter table staff
add constraint pk_yg primary key(id)
alter table salary
add constraint U_xinzname unique(Saname)
alter table salary
add constraint DF_jichu default 1200 for bsalary
alter table salary
add constraint CK_shifa check (Psalary<Sapayabl)
alter table staff
add constraint CK_phone
check (phone like'[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
alter table salary
with nocheck
add constraint CK_nock check (Psalary<Sapayabl)
alter table staff
add constraint FK_xinji
foreign key(salaryid) references salary (salaryid)
alter table staff
add constraint FK_xinji
foreign key(salaryid) references salary (salaryid)
on delete cascade
on update cascade
|
2、在students数据库上,使用SQL语句完成下列操作:#
(1)为Sc表中的Sno添加外码约束,引用Student表的Sno;为Sc表添加外码约束,引用Course表的Cno。
1
2
3
4
| alter table Sc
add constraint FK_sc
foreign key(Sno) references Student(Sno),
foreign key(Cno) references Course(Cno)
|
(2)为Student表中的Sname列添加唯一约束,使其值不重复。
1
2
| alter table Student
add constraint U_sname unique(Sname)
|
(3)为Sc表中的Grade列添加CHECK约束,使其值为0~100。
1
2
| alter table Sc
add constraint CK_grade check (Grade between 1 and 100)
|
(4)为Student表中的Sage列添加DEFAULT约束,使其默认值为19。
1
2
| alter table Student
add constraint DF_sage default 19 for Sage
|
(5)删除第(4)题中的DEFAULT约束。
1
| alter table Student drop DF_sage
|