当前位置:首页 » 编程语言 » sql联系

sql联系

发布时间: 2022-01-08 10:21:24

❶ 求几个sql文件,就是有数据的,拿来练习SQL语句

邮件已经发出,过几分钟后记得查收(可能在垃圾箱里边),收到后觉得还算满意请点下边的采纳通知我。如果10分钟后还没收到,请直接在本问题里追问我,我会再次发送。
如果还有需要的朋友,请点“赞”此条回答以后,在下面的评论里留下您的联系方式即可!
最后如果在采纳之余能加点分数,那就更好啦!

❷ 谁有sql 语句练习题,越多越好!

额 我只晓得SQLServer的T-SQL
中文版SQL Server 2000开发与管理应用实例
http://www.china-pub.com/26313
都是大量项目中能用到的实例
CSDN SQL大版主的书籍,可说非常不错了
希望对你有帮助

如果还要再深入理解点原理东西
可以看下 微软技术丛书sql2005 T-SQL查询与T-SQL程序设计

❸ SQL入门怎么练习

自己安装一个SQL SERVER然后按照书上的一点一点执行,先从最基本的开始

❹ 想学习SQL语言,该用什么软件来练习SQL语句

电脑上装个Mysql。然后再装Navicat for MySQL
或者SQLyog这个csdn上也有汉化的

❺ 如何在一台电脑上练习SQL语句

1.选择你想安装的 sql2000。或是sql 2005

2.安装成功后,打开sql server 服务管理器,然后开启

3.企业管理器 然后 就可以 创建数据库 表了

4.也可以在 查询分析器里面 写查询语句,但是要找到 对应的数据库 来查询

❻ 想练习SQL,有没有什么网上数据库是能直接拿来练习SQL的

建议安装一个EasyAPM-Server v2.1.0 RC,你就可以随便练习操作sql数据库了。
地址:http://www.opticsky.cn/htm_data/37/0601/2347.html

❼ sql练习!!!

alter talbe stuscore
add constraint ch_a check(english<100 and english>0)
select * from stuinfo where name like '张%' and sex = '男'
select time from stuinfo where name = '刘k'
……………………
……………………
只能到这里了,仅供参考

❽ 我想练习sql语句,请问如何做呢

安装一个数据库服务器,建立一个库。
然后先做这些练习吧,语句都加了注释了
/*
建立一个由3个文件组成的数据库,数据库名称为test。
主数据文件逻辑名称为test_data,物理文件名c:\test_data.mdf;
辅助数据文件逻辑名称为test_data2,物理文件名c:\test_data2.ndf;
日至文件逻辑名称为test_log,物理文件名c:\test_log.ldf;
所有文件初始尺寸为3mb,可以自动增长,最大尺寸为15mb。
*/
create database test on
primary
(
name=test_data,
filename='c:\test_data.mdf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
),
(
name=test_data2,
filename='c:\test_data2.ndf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
)
log on
(
name=test_log,
filename='c:\test_log.ldf',
size=3mb,
maxsize=15mb,
filegrowth=1mb
)

/*
创建一个名为employees的表,该表由5个字段组成:emp_id(员工编号)、ename(员工名称)、
age(年龄)、title(职务)、salary(薪水)。其中emp_id为该表的主键。该表存放在主文件组。
*/
use test
go
CREATE TABLE employees(
emp_id char (4) primary key,
ename nvarchar (10) NOT NULL,
age tinyint NOT NULL,
title nvarchar (10) NULL,
salary money NULL,
) ON [PRIMARY]

--向employees表插入部分数据
insert into employees values('0001','杨建新','22','经理','3000')
insert into employees values('0002','杨建新','23','职员','4000')
insert into employees values('0003','杨建新','24','总经理','5000')
insert into employees values('0004','杨建新','26','职员','2000')

--创建备份设备test_bak,其位置为c:\backup\test_bak.bak
sp_admpdevice 'disk','test_bak','c:\backup\test_bak.bak'

--建立数据库test的完整备份到备份设备test_bak,并命名为test_full_bak1
backup database test to test_bak with name='test_full_bak1'

--向employees表插入新数据
insert into employees values('0005','王建新','24','总经理','1000')
insert into employees values('0006','刘建新','26','职员','2000')

--执行test数据库的事务日志备份,该备份追加到备份设备test_bak,命名为test_log_bak1
backup log test to test_bak with name='test_log_bak1'

--截断employees表,清空内容(记录此时的时间)
truncate table employees

--备份数据库的尾部日志
use master
go
backup log test to test_bak with name='test_log_recovery',norecovery

--恢复数据库的完整备份,并且不要执行还原进程(norecovery)
restore database test from test_bak with file=1,norecovery

--恢复第一个日志备份,如果此时执行recovery,将得到所有数据
restore log test from test_bak with file=2,recovery

--如果执行上述语句时,使用norecovery选项,则可以继续恢复第二个日志备份,即尾部日志
restore log test from test_bak with file=2,norecovery
restore log test from test_bak with file=3,recovery

--如果按照上述操作,则恢复完成后employees表中没有任何数据,因为尾部日志中包含清空表的操作
--若要恢复所有数据,也可以恢复到时间点到清空时间之前
restore log test from test_bak with file=3,stopat='2008-11-16 11:25:00'

--添加一个名为mike,密码为123456的login账户,该账户的默认数据库为northwind
sp_addlogin 'mike','123456','northwind'
--切换到northwind数据库
use northwind
go
--将登录账户mike映射为当前数据库中的用户
sp_grantdbaccess 'mike','mike' --或:sp_adser 'mike','mike'
--建立数据库角色accessdata
sp_addrole tablecreate
--为数据库角色tablecreate赋予创建表的权限
grant create table to tablecreate
--将用户mike加入到角色tablecreate中
sp_addrolemember 'tablecreate','mike'
--赋予用户mike对procts表的插入数据权限
grant insert on procts to mike
--撤销用户mike对procts表的权限
revoke insert on procts from mike
--察看角色信息
sp_helprole tablecreate
--察看角色包括的成员
sp_helprolemember tablecreate
--在角色tablecreate中删除成员mike
sp_droprolemember 'tablecreate','mike'
--删除角色tablecreate
sp_droprole tablecreate
--删除数据库用户账户
sp_revokedbaccess 'mike'
--删除登录帐号
sp_droplogin 'mike'

❾ SQL练习题

一 学生 – 课程数据库
1 查询 7号课程没有考试成绩的学生学号
select sno from sc where cno=’7’ and grade is not null
2 查询 7号课程成绩在90分以上或60分以下的学生学号
select sno from sc where grade>90 or grade<60
3 查询课程名以“数据”两个字开头的所有课程的课程号和课程名。
Select cno,cname from c where cname like ‘数据%’
4 查询每个学生所有课程的平均成绩,输出学生学号、平均成绩
select sno,avg(grade) from sc group by sno
5 查询每门课程的选修人数,输出课程号、选修人数。
Select cno,count(*) from sc group by cno
6 查询选修 7号课程的学生的学号、姓名、性别。
Select s.sno, sname,ssex from s , sc where s.sno=sc.sno and cno = ‘7’
7 查询选修7号课程学生的平均年龄。
Select avg(sage) from s , sc where s.sno=sc.sno and cno = ‘7’
8 查询由30名以上学生选修的课程号。
Select sno from sc group by cno having count(*)>30
9 查询至今没有考试不及格的学生学号
a: select sno from s where sno not in ( select sno from sc where grade<60 )
b: select sno from sc group by sno having min(grade)>=60

1 找出选修课程号为 C2 的学生学号与成绩。
Select sno,grade from sc where cno=’C2’
2 找出选修课程号为C4 的学生学号与姓名。
Select s.sno , sname from s,sc where s.sno=sc.sno and cno=’C4’
3 找出选修课程名为 Maths 的学生学号与姓名。
Select s.sno ,sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and cname = ‘Maths’
4找出选修课程号为C2或C4 的学生学号。
Select distinct sno from sc where cno in (‘C2’,’C4’)
或: Select distinct sno from sc where cno=’C2’ or cno =’C4’
5找出选修课程号为C2和C4 的学生学号。
Select sno from sc where cno =’C2’ and sno in (
select sno from sc where cno = ‘C4’ )
6 找出不学C2课程的学生姓名和年龄
select sname , sage from s where sno not in ( select sno from sc where cno=’C2’ )
或:
select sname , sage from s where not exists ( select * from sc where sc.sno=s.sno and cno=’C2’ )
7 找出选修了数据库课程的所有学生姓名。(与3同)
Select s.sno ,sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and cname = ‘数据库’

8 找出数据库课程不及格的女生姓名
嵌套:
select sname from s where ssex = ‘女’ and sno in ( select sno from sc where grade<60 and cno in ( select cno from c where cname=’数据库’) )
连接:
Select sname from s,sc,c
where s.sno=sc.sno and c.cno=sc.cno and ssex=’女’ and cname = ‘数据库’ and grade<60
9 找出各门课程的平均成绩,输出课程名和平均成绩
select cname , avg(grade) from sc , c where c.cno =sc.cno group by sc.cno
10找出各个学生的平均成绩,输出学生姓名和平均成绩
select sname , avg(grade) from s , sc where s.sno=sc.sno group by sc.sno
11 找出至少有30个学生选修的课程名
select cname from c where cno in ( select cno from sc group by cno having count(*)>=30 )
12 找出选修了不少于3门课程的学生姓名。
Select sname from s where sno in ( select sno from sc group by sno having count(*)>=3)
13 找出各门课程的成绩均不低于90分的学生姓名。
Select sname from s where sno not in ( select sno from sc where grade<90)
14* 找出数据库课程成绩不低于该门课程平均分的学生姓名。
Select sname from s where sno in (
Select sno from sc , c where sc.cno=c.cno and cname=’数据库’ and
Grade > (Select avg(grade) from sc , c where sc.cno=c.cno and cname=’数据库’ ) )
15 找出各个系科男女学生的平均年龄和人数。
Select sdept,ssex , avg(sage) , count(*) from s
Group by sdept , ssex
16 找出计算机系(JSJ)课程平均分最高的学生学号和姓名。
Select sc.sno , sname from s, sc where s.sno=sc.sno and sdept=’JSJ’
Group by sc.sno Having avg(grade) =
( Select top 1 avg(grade) from sc, s where s.sno=sc.sno and sdept=’JSJ’
group by sc.sno order by avg(grade) DESC )
三 客户 – 商品数据库中包括3按各表:KH,FP,YWY
1 查询工资在 1000 到3000 元之间的男性业务员的姓名和办公室编号。
Select Yname , Ono from YWY where salary between 1000 and 3000 and Ysex=’男’
2 查询各个办公室的业务员人数,输出办公室编号和对应的人数。
Select Ono , count(*) from YWY group by Ono
3 查询每个客户在2002年5月购买的总金额,输出客户号和相应的总金额。
Select Kno,sum(Fmoney) from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’
Group by Kno
4 查询2002年5月购买次数超过5次的所有客户号,且按客户号升序排序。
Select Kno from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’
Group by Kno having count(*)>5
Order by Kno ASC
5 查询各办公室男性和女性业务员的平均工资。
Select Ono,Ysex ,avg(salary) from YWY group by Ono , Ysex
6 查询2002年5月曾经在王海亮业务员手中购买过商品的客户号、客户姓名、联系电话。
Select Kno,Kname,phone from KH where Kno in (
Select kno from FP where fdate between ‘2002.5.1’ and ‘2002.5.31’ and
Yno=(select Yno from YWY where Yname = ‘王海亮’ )
7 查询所有工资比1538号业务员高的业务员的编号、姓名、工资。
Select yno ,Yname, salary from YWY where salary >
( Select salary from YWY where Yno=’1538’ )
8 查询所有与1538号业务员在同一个办公室的其他业务员的编号、姓名。
Select Yno , Yname from YWY where Yno<>’1538’ and Ono in (
Select Ono from YWY where Yno=’1538’ )
9 查询销售总金额最高的业务员的编号。
Select Yno from FP Group By Yno Having sum(Fmoney) =
(Select top 1 sum(Fmoney) from FP group by Yno ORDER BY sum(Fmoney) DESC)
10 查询所有业务员的编号、姓名、工资以及工资比他高的其他业务员的平均工资。
利用自身连接
Select y1.Yno ,y1.Yname ,y1.salary , avg( y2. salary) from YWY y1 , YWY y2
Where y1.Yno<>y2.Yno and y1.salary < y2.salary
Group by y1.Yno
Sno salary sno salary
1 100 1 100
2 120 2 120
3 90 3 90
4 110 4 110
四 某中学数据库中由一张表:
学生选课表:由板及代码、班内学号、姓名、科目、成绩五个属性组成,关系模式为
SC(BJDM,BNXH,XSXM,KM,CJ) ,其中(BJDM,BNXH)为主码。
说明:每个学生每门科目存放一个记录,科目有“语文”、“数学”、“外语”三门。
1 找出每个班级的班级代码、学生人数、平均成绩。
Select BJDM,count(*) ,avg(CJ) from SC group by BJDM
2 找出每个学生的班级代码、学生姓名、考试科目数、总成绩。
Select BJDM,XSXM,count(*) , sum(CJ) from SC
Group by BNXH
3 输出一张表格,每位学生对应一条记录,包括:班级代码、姓名、语文成绩、数学成绩、外语成绩。
方法一:利用视图
create view v1 (bjdm,xsxm, yw,sx,wy ) AS
select bjdm , xsxm , cj , 0,0 from sc where km=’语文’
union
select bjdm , xsxm , 0 , cj,0 from sc where km=’数学’
union
select bjdm , xsxm , 0,0,cj from sc where km=’外语’

select bjdm, xsxm , sum(yw) as 语文, sum(sx) as 数学, sum(wy) as 外语 from v1 group by bjdm, xsxm
方法二:自身连接
select a.bjdm,a.xsxm , a.km,a.cj , b.km,b.cj , c.km,c.cj from sc a , sc b , sc c
where a.bjdm=b.bjdm and a.bnxh= b.bnxh and b.bjdm=c.bjdm and b.bnxh= c.bnxh
and a.km=’语文’ and b.km=’数学’ and c.km=’外语’
方法三:利用存储过程(略)
4 输出一张表格:由成绩低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、最低成绩。
Select bjdm,xsxm ,min(CJ) from sc where grade<60 group by bjdm,xsxm
5输出一张表格:由成绩低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、最高成绩、平均成绩。
得到平均成绩:create view V1 (bjdm,bnxh ,avg_cj) AS
select bjdm,bnxh ,avg(cj) from sc where bjdm , bnxh
select sc.bjdm,sc.xsxm ,max(cj) , avg_cj from sc , V1
where sc.bjdm=v1.bjdm and sc.bnxh=V1.bnxh and cj<60
group by sc.bjdm,sc.xsxm
6输出一张表格:所有成绩不低于60分的每位学生对应一条记录,包括字段:班级代码、姓名、平均成绩。
select bjdm, xsxm , avg(cj) from sc
where sno not in ( select sno from sc where grade<60)
group by bjdm, xsxm
7输出一张表格:每一位学生对应一条记录,包括字段:班级代码、姓名、去掉一个最低分后的平均成绩。
方法一:
得到每个学生的最低分:
create view V1 (bjdm,bnxh ,min_cj) as
select bjdm,bnxh,min(cj) from sc group by bjdm,bnxh
select sc.bjdm,sc.xsxm , avg(cj) from sc , v1
where sc.bjdm=v1.bjdm and sc.bnxh=v1.bnxh and sc.cj <> v1.min_cj
group by bjdm,bnxh
方法二:
select sc.bjdm,sc.xsxm , ( sum(cj) – min(cj) ) / count(*) from sc
group by bjdm , bnxh
8输出一张表格:每门科目对应一条记录,包括字段:科目、去掉一个最低分后的平均成绩。
方法一:
得到每门课的最低分:
create view V1 ( km, min_cj) as
select km,min(cj) from sc group by km
select sc.km , avg(cj) from sc , v1
where sc.km=v1.km and sc.cj <> v1.min_cj
group by sc.km
方法二:
select km , (sum( cj) – min(cj) )/count(*) from sc
group by km
补充9:输出表格:每门科目对应一条记录,包括字段:科目、去掉一个最低分和最高分后的平均成绩。
select km , (sum( cj) – min(cj) – max(cj) )/count(*) from sc
group by km
五 数据库存放着某高校1990年以来英语四、六级的考试情况,且规定:
1 英语四、六级考试每年分别在6月和12月举行二次;
2 四级没有通过的学生不能报考六级;
3 某一级的考试只要没有通过可以反复参加考试;
4 某一级的考试一旦通过就不能再报考同级的考试;
5 允许报了名但不参加考试。
该数据库中有二张表,相应的关系模式如下:
学生表:S(Sno, Sname, Ssex, Sage, Sdept),其中Sno为主码。
考试表:E(Sno, Year, Month, Level, Grade),学号、年、月、级别、成绩。
其中(Sno, Year, Month)为主码。
1. 找出各次四级和六级考试的参考人数和平均成绩(报了名但没有参加考试的不作统计)
select year , month,level ,count(*) , avg(grade)
group by year,month , level
2. 找出各次四级考试中平均分最高的系科(报了名但没有参加考试的不作统计)。
A: Select sdept from s , e where s.sno=e.sno
Where level=4
Group by sdept
Having avg(grade)>=ALL(
Select avg(grade) from s , e where s.sno=e.sno where level=4 Group by sdept )
B: Select top 1 sdept from s , e where s.sno=e.sno
Where level=4
Group by sdept
Order by (avg(grade) desc
3. 找出已经通过英语六级考试的学生的学号、姓名和性别(用连接方法做)
select s.sno,sname,ssex from s,e
where s.sno=e.sno and level=6 and grade>=60
4. 找出在同一年中四、六级考试都参加了的学生的学号
1) select sno from E
where (level=4 and grade>=60) or level=6
group by year having count(*)>=2
2) select sno from E X where level=4 and grade>=60 and exists (
select * from E Y where Y.sno=X.sno and year=X.year and level=6 )
5. 找出只参加一次考试就通过了英语六级考试的学生的学号
select sno from E
where level=6
group by sno
having count(*)=1 错,想想为何?
1) select sno from E
where level=6
group by sno
having count(*)=1 and max(grade)>=60
2) select sno from E where level=6 and grade>=60 and sno in (
select sno from E where level=6 group by sno having count(*)=1)
6. 找出至今没有通过英语四级考试的学生的学号(应包括至今还没有参加过考试或者是参加了但还没有通过两种)
select sno from E where level=4
group by sno
having max(grade)<60
Union
Select sno from s where sno not in( select sno from E)
7. 找出英语六级考试中合格人数最少的考试年份和月份(有并列的都要列出,用一句SQL语句)。
Select year , month From E
Where level = 6 and grade>=60
Group by year , month
Having count(*) <=all
(Select count(*) from E where level=6 and grade>=60 group by year , month )

我是从“上海全鼎软件学院”毕业的————————

热点内容
单片机android 发布:2024-09-20 09:07:24 浏览:760
如何提高三星a7安卓版本 发布:2024-09-20 08:42:35 浏览:661
如何更换服务器网站 发布:2024-09-20 08:42:34 浏览:308
子弹算法 发布:2024-09-20 08:41:55 浏览:286
手机版网易我的世界服务器推荐 发布:2024-09-20 08:41:52 浏览:814
安卓x7怎么边打游戏边看视频 发布:2024-09-20 08:41:52 浏览:160
sql数据库安全 发布:2024-09-20 08:31:32 浏览:91
苹果连接id服务器出错是怎么回事 发布:2024-09-20 08:01:07 浏览:505
编程键是什么 发布:2024-09-20 07:52:47 浏览:655
学考密码重置要求的证件是什么 发布:2024-09-20 07:19:46 浏览:479