1018sql语言

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