1018sql语言
CREATE TABLE student
(
sno char(20) primary key,
sname char(8),
ssex char(2),
sage int,
sdept char(2)
);
create table course
(
cno int primary key,
cname char(30),
cpno int,
ccredit int
foreign key (cpno) references course(cno)
);
create table sc
(
sno char(20),
cno int,
grade int,
primary key(sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno),
);
insert into student values ('201215121','李勇','男',20,'CS');
insert into student values ('201215122','刘晨','女',19,'CS');
insert into student values ('201215123','王敏','女',18,'MA');
insert into student values ('201215125','张立','男',19,'IS');
insert into sc values ('201215121', 1, 92);
insert into sc values ('201213121', 2, 85);
insert into sc values ('201216121', 3, 88);
insert into sc values ('201215122', 2, 90);
insert into sc values ('201214122', 3, 80);
insert into course values (1,'数据库',5,4);
insert into course values (2,'数学',null,4);
insert into course values (3,'信息系统',1,4);
insert into course values (4,'操作系统',6,3);
insert into course values (5,'数据结构',7,4);
insert into course values (6,'数据处理',null,2);
insert into course values (7,'PASCAL语言',6,4);
insert into student
(sno, sname, ssex,sage,sdept,TELE)
values
('201215121','李勇','男',20,'CS','123456789');
select * from student;
alter table student add TELE varchar(20);
/*
(2)为student表以sdept建立一个名为sdeptin的索引;
(3)为course表以cname建立一个名为cnamein的唯一索引;
*/
create unique index sdeptin on student(sdept);
create unique index cnamein on course(cname);
select * from student;
select * from sc;
select * from course;
select * from S_table;
select * from P_table;
select * from J_table;
select * from SPJ;
create table spj(
sno varchar(10),
pno varchar(10),
jno varchar(10),
);
create table S_table(
sno varchar(4) primary key,
sname varchar(10),
status int,
city varchar(10),
);
create table P_table(
pno varchar(4) primary key,
pname varchar(10),
color varchar(4),
weight int,
);
create table J_table(
jno varchar(20) primary key,
jname varchar(20),
city varchar(10),
);