专业课学习——建立 SCT 数据库
生活随笔
收集整理的這篇文章主要介紹了
专业课学习——建立 SCT 数据库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
建立 SCT 數據庫
/* 創建學生表并添加數據*/ create table Student( Sno char(9) primary key, Sname nvarchar(40) not null, Ssex char(2) default ('男'), Sage smallint, Sdept nvarchar(20), ); 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'); /* 創建課程表并添加數據*/ create table Course ( Cno char(4) not null, Cname char(40) not null, Cpno char(4) , Credit smallint check (Credit >= 0), primary key(Cno), foreign key (Cpno) references Course(Cno) );insert into Course(Cno, Cname, Credit) values('1', '數據庫', 4); insert into Course(Cno, Cname, Credit) values('2', '數學', 2); insert into Course(Cno, Cname, Credit) values('3', '信息系統', 4); insert into Course(Cno, Cname, Credit) values('4', '操作系統', 3); insert into Course(Cno, Cname, Credit) values('5', '數據結構', 4); insert into Course(Cno, Cname, Credit) values('6', '數據處理', 2); insert into Course(Cno, Cname, Credit) values('7', 'PASCAL語言', 4);update Course set Cpno = 5 where Cno = 1; update Course set Cpno = 1 where Cno = 3; update Course set Cpno = 6 where Cno = 4; update Course set Cpno = 7 where Cno = 5; update Course set Cpno = 6 where Cno = 7;/* 創建成績表并添加數據*/ create table SC( Sno char(9), Cno char(4), Grade int check(Grade >= 0 and Grade < 100), primary key (Sno , Cno), foreign key (Sno) references Student(Sno), foreign key (Cno) references Course(Cno) );insert into SC values('201215121', '1', 92); insert into SC values('201215121', '2', 85); insert into SC values('201215121', '3', 88); insert into SC values('201215122', '2', 90); insert into SC values('201215122', '3', 80);數據庫實驗
/* 單表查詢2*/ select Sname from Student where Sage < 20; select Sno, avg(Grade) from SC group by Sno; select * into gileStudent from Student where Ssex = '女'; /* 連接查詢*/總結
以上是生活随笔為你收集整理的专业课学习——建立 SCT 数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【PPP-RTK技术研究进展与实验验证】
- 下一篇: playbook_黑莓PlayBook的