成熟丰满熟妇高潮XXXXX,人妻无码AV中文系列久久兔费 ,国产精品一国产精品,国精品午夜福利视频不卡麻豆

您好,歡迎來到九壹網(wǎng)。
搜索
您的當前位置:首頁常用SQL語句查詢分享

常用SQL語句查詢分享

來源:九壹網(wǎng)

--創(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 = '小張'); 

--子查詢中間的符號一定是父查詢與子查詢兩張表關(guān)聯(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=''
)
)
);

您可能感興趣的文章:

  • SQL查詢語句通配符與ACCESS模糊查詢like的解決方法
  • SQL Server SQL高級查詢語句小結(jié)
  • SQLSERVER查詢所有數(shù)據(jù)庫名,表名,和字段名的語句
  • mysql like查詢字符串示例語句
  • MySql日期查詢語句詳解
  • mysql分頁原理和高效率的mysql分頁查詢語句
  • 用SQL語句查詢數(shù)據(jù)庫中某一字段下相同值的記錄方法
  • 只有兩個字段用一個sql語句查詢出某個學生的姓名、成績以及在表中的排名
  • Copyright ? 2019- 91gzw.com 版權(quán)所有 湘ICP備2023023988號-2

    違法及侵權(quán)請聯(lián)系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

    本站由北京市萬商天勤律師事務所王興未律師提供法律服務