create database s_t1
use s_t1
create table student
(Sno char(9) primary key ,
Sname char(6) not null,
Ssex char(2),
Sage int,
Sdept varchar(8));
create table course
(
Cno char(4) primary key,
Cname varchar(20) not null,
Cpno char(4) ,
Ccreat int
)
create table sc
(
Sno char(9) ,
Cno char(4) ,
Grade int ,
primary key (Sno,Cno)
)
alter table course
add constraint FK_cpno_course foreign key (Cpno) references course(Cno);
alter table sc
add constraint FK_sno_student foreign key (Sno) references student(Sno)
alter table course
add constraint FK_cno_course foreign key (Cno) references course(Cno)
alter table student
add sclass varchar(10);
alter table student drop column sclass ;
alter table student
alter column sname char(8);
alter table student
alter column Sdept varchar(20)
exec sp_rename 'student.Sdept','dept','column';
alter table student
add constraint CK_sage Check (sage between 16 and 40) ;
alter table student
drop constraint CK_sage;
alter table student
alter column sage smalldatetime
exec sp_rename 'student.sage', 'sbirth','column';
exec sp_rename 'student','stu_info';
drop table 'stu_info';
|