1 Create Table student 2 ( 3 Sno char (9) Primary key , 4 Sname char (20) Unique , 5 Ssex char (2) , 6 Sage smallint , 7 Sdept char(20) 8 9 ); 10 11 Create Table Course 12 ( 13 Cno char (4) Primary key , 14 Cname char (40) not Null , 15 Cpno char (4) , 16 Ccredit smallint 17 foreign key (Cpno) References Course(Cno) 18 ); 19 20 Create Table SC 21 ( 22 Sno char (9) , 23 Cno char (4) , 24 Grade smallint 25 26 Primary key ( Sno , Cno ) , 27 Foreign key ( Sno ) References Student (Sno), 28 Foreign key ( Cno ) References Course (Cno) 29 30 ); 31 32 Insert Into student(Sno,Sname,Ssex,Sage,Sdept) 33 values('201215121','李勇','男',20,'CS'); 34 Insert Into student(Sno,Sname,Ssex,Sage,Sdept) 35 values('201215122','刘晨','女',19,'CS'); 36 Insert Into student(Sno,Sname,Ssex,Sage,Sdept) 37 values('201215123','王敏','女',18,'MA'); 38 Insert Into student(Sno,Sname,Ssex,Sage,Sdept) 39 values('201215125','张立','男',19,'IS'); 40 41 42 Insert Into Course(Cno,Cname,Cpno,Ccredit) 43 values('2','数学',NULL,2) 44 Insert Into Course(Cno,Cname,Cpno,Ccredit) 45 values('6','数据处理',NULL,2) 46 Insert Into Course(Cno,Cname,Cpno,Ccredit) 47 values('4','操作系统','6',3) 48 Insert Into Course(Cno,Cname,Cpno,Ccredit) 49 values('7','PASCAL语言','6',4) 50 Insert Into Course(Cno,Cname,Cpno,Ccredit) 51 values('5','数据结构','7',4) 52 Insert Into Course(Cno,Cname,Cpno,Ccredit) 53 values('1','数据库','5',4) 54 Insert Into Course(Cno,Cname,Cpno,Ccredit) 55 values('3','信息系统','1',4) 56 57 /* 58 drop table SC; 59 drop table Course; 60 drop table student; 61 */ 62 63 64 Insert Into SC(Sno,Cno,Grade) 65 values ( '201215121' , '1' , 92 ) 66 Insert Into SC(Sno,Cno,Grade) 67 values ( '201215121' , '2' , 85 ) 68 Insert Into SC(Sno,Cno,Grade) 69 values ( '201215121' , '3' , 88 ) 70 Insert Into SC(Sno,Cno,Grade) 71 values ( '201215122' , '2' , 90 ) 72 Insert Into SC(Sno,Cno,Grade) 73 values ( '201215122' , '3' , 80 )
相关文章: