最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

常用SQL語句查詢分享

 更新時間:2016年01月13日 10:33:01   投稿:hebedich  
本文通過幾個小例子,給大家分享一下常用SQL常用的語句,非常的簡單實用,有需要的小伙伴可以參考下。

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

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

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

--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)建分數(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)合查詢:等值查詢
--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>=60
and s.sid = sc.sid and c.cid = sc.cid;

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

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

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

--4..

update sc set score=score+5 where cid=????;

select tid from teacher where tname='李老師' ==1
select cname from course where tid = 1 ==課程名字,李老師教的
select cid from course where cname='android' ==課程ID
update 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='李老師'
)
)
);

相關文章

最新評論

汤原县| 乌恰县| 大洼县| 巴林右旗| 车致| 济阳县| 景泰县| 丰都县| 香港| 宣化县| 辽宁省| 仙居县| 合作市| 兴海县| 平凉市| 贵南县| 定安县| 铜鼓县| 大田县| 磐安县| 塔城市| 隆回县| 平顺县| 天全县| 六安市| 改则县| 玉屏| 鱼台县| 岢岚县| 枣阳市| 崇礼县| 株洲县| 柞水县| 岱山县| 邵阳县| 山丹县| 土默特右旗| 邮箱| 尚志市| 西峡县| 阆中市|