选课表(sc)
列名含义数据类型约束Sno学号char(11)主码,引用student的外码Cno课程号char(6)主码,引用course的外码Grade成绩tinyint 创建sc表代码: use student create table sc ( Sno char(11) not null, Cno char(6) not null, Grade tinyint, primary key (sno,cno), foreign key (sno) references student(sno), foreign key (cno) references course(cno) )
(2)为sc表添加‘修课类别’(type)列,允许为空,代码如下: alter table sc add type nchar(1) null
(3)为sc表添加‘修课类别’(type)列修改他的数据类型为nchar(2),代码如下: alter table sc alter column type nchar(2)
(4)为sc表添加‘修课类别’(type)列添加取值范围为{必修,重修,选修}的约束,代码如下: alter table sc add check(type in ('必修','重修','选修'))
(5)删除type列,代码如下: alter table sc drop column type