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

首頁(yè) > 數(shù)據(jù)庫(kù) > SQL Server > 正文

常用SQL語(yǔ)句查詢(xún)分享

2024-08-31 01:03:38
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
本文通過(guò)幾個(gè)小例子,給大家分享一下常用SQL常用的語(yǔ)句,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
 

--創(chuàng)建數(shù)據(jù)庫(kù)(文件:主要數(shù)據(jù)文件mdf==1,次要數(shù)據(jù)文件ndf>=0,日志文件ldf>=1)
--文件組:當(dāng)1mdf,5個(gè)ndf(1,2,2),10個(gè)ldf(3,3,4),將它們分成多個(gè)組存放

CREATE database studb;

--創(chuàng)建表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) );

--外鍵約束:你問(wèn)張三的老師是誰(shuí)??

--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

--創(chuàng)建課程表

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

--創(chuàng)建分?jǐn)?shù)表

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

--聯(lián)合查詢(xún):等值查詢(xún)
--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..
--子查詢(xún):當(dāng)條件也要查詢(xún)的時(shí)候,我只知道學(xué)號(hào),我不知道"小張"這個(gè)字段,那你知道小張的學(xué)號(hào) 嗎

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

--子查詢(xún)中間的符號(hào)一定是父查詢(xún)與子查詢(xún)兩張表關(guān)聯(lián)的字段(一般是主外鍵)

--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='李老師')));


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到MSSQL教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 巍山| 平阴县| 榆林市| 凭祥市| 南安市| 玉门市| 翁源县| 五家渠市| 根河市| 东兰县| 苗栗市| 宁国市| 新龙县| 武安市| 张家川| 施甸县| 遵义县| 沧州市| 慈溪市| 莱州市| 沛县| 崇文区| 若羌县| 莱州市| 五指山市| 专栏| 广州市| 枣强县| 漳浦县| 团风县| 文水县| 黑龙江省| 岳池县| 扎鲁特旗| 北流市| 金堂县| 新余市| 南皮县| 修武县| 乌鲁木齐县| 绥棱县|