为了方便练习相应语句,写下此博文,用于快速建立一个简单的数据库。
create table Student
(
Sno char(10)primary key,
Sname char(10) unique,
Ssex char(2) check (Ssex in ('男','女')),
Sage smallint check(Sage between 18 and 20),
Sdept char(20),
);
create table Course(
Cno char(4) primary key,
Cname char(20) not null,
Cpno char(4),
Ccredit smallint,
foreign key (Cpno) references Course(Cno),
);
create table SC(
Sno char(10),
Cno char(4),
Grade smallint,
primary key(Sno,Cno),
foreign key(Sno) references Student(Sno),
foreign key(Cno) references Course(Cno)
);
insert into dbo.Student(Sno, Sname, Ssex, Sage, Sdept)
values('60001','zhangsan','女',18,'art'),
('60002','lisi','女',18,'it'),
('60003','wangwu','女',18,'art'),
('60004','chenliu','女',18,'pe'),
('60005','tisi','女',18,'pe');
INSERT INTO