国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

常用SQL語句查詢分享

2020-07-25 12:47:48
字體:
來源:轉載
供稿:網友

--創建數據庫(文件:主要數據文件mdf==1,次要數據文件ndf>=0,日志文件ldf>=1)
--文件組:當1mdf,5個ndf(1,2,2),10個ldf(3,3,4),將它們分成多個組存放

CREATE database studb;

--創建表teacher,student

create table teacher(tid int(10) primary key auto_increment,tname varchar(20),tage int(10));use studb;
create table student(sid int(10) primary key auto_increment,sname varchar(20),sage int(10),tid int(10) REFERENCES teacher(tid) );

--外鍵約束:你問張三的老師是誰??

--select teacher.tname from teacher,student where student.sname = '張三'select t.tname from teacher t,student s where s.sname = '張三' and t.tid = s.tid

--創建課程表

create table course(cid int(10) primary key,cname varchar(20),tid int(10) REFERENCES teacher(tid));

--創建分數表

create table sc(scid int(10) primary key,sid int(10) REFERENCES student(sid),cid int(10) REFERENCES course(cid),score int(10));

--聯合查詢:等值查詢
--1..

select c.cname from course c,student s,sc where s.sname = '小張' and s.sid = sc.sid and c.cid = sc.cid;

--2..

select sname from student s,course c,sc where c.cname='android' and sc.score>=60and s.sid = sc.sid and c.cid = sc.cid;

--3..
--子查詢:當條件也要查詢的時候,我只知道學號,我不知道"小張"這個字段,那你知道小張的學號 嗎

delete from sc where sid = (select sid from student where sname = '小張'); 

--子查詢中間的符號一定是父查詢與子查詢兩張表關聯的字段(一般是主外鍵)

--4..

update sc set score=score+5 where cid=????;select tid from teacher where tname='李老師' ==1select cname from course where tid = 1 ==課程名字,李老師教的select cid from course where cname='android' ==課程IDupdate sc set score=score+5 where cid=(select cid from course where cname=(select cname from course where tid =(select tid from teacher where tname='李老師')));

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 邓州市| 军事| 尚志市| 巴马| 宜川县| 定州市| 同心县| 阿克| 昌黎县| 吴江市| 商水县| 常德市| 化德县| 鄂伦春自治旗| 高青县| 金溪县| 潮安县| 来安县| 阜康市| 普定县| 晋城| 东平县| 松阳县| 玉树县| 望城县| 老河口市| 广平县| 红安县| 瓮安县| 德州市| 讷河市| 陆河县| 永修县| 连州市| 荆门市| 青河县| 昭平县| 莆田市| 玉门市| 冀州市| 文昌市|