首页数据库sql数据库经典例题?sql高级查询50道题

sql数据库经典例题?sql高级查询50道题

编程之家2026-05-14901次浏览

这篇文章给大家聊聊关于sql数据库经典例题,以及sql高级查询50道题对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

sql数据库经典例题?sql高级查询50道题

SQL数据库试题求解

------------------------------------------------------

create table students(st_id varchar(20),st_name varchar(50),sex varchar(10))

insert into students(st_id,st_name,sex)

select'st001','张杰','男' union all

select'st002','公孙燕飞','男' union all

select'st003','王楠','女' union all

sql数据库经典例题?sql高级查询50道题

select'st004','王伟','男' union all

select'st005','李燕纹','女' union all

select'st006','孙武','男'

select*

from students

create table teachers(t_id varchar(20),t_name varchar(50),t_lesson varchar(50))

sql数据库经典例题?sql高级查询50道题

insert into teachers

select't001','张老师','数学' union all

select't002','李老师','英语'

delete from results

create table results(r_id varchar(20),r_fenshu int,r_stid varchar(50),r_tid varchar(50))

insert into results

select'r001','90','st001','t002' union all

select'r002','68','st005','t001' union all

select'r003','92','st003','t001' union all

select'r004','82','st006','t002' union all

select'r005','70','st002','t002' union all

select'r006','86','st002','t001' union all

select'r007','57','st003','t002' union all

select'r008','76','st006','t001' union all

select'r009','55','st001','t001' union all

select'r010','77','st004','t002' union all

select'r011','58','st005','t002'

----------------------------------------------------------

1.

select st_id

from students

where st_name='王伟'

2.select st_id,st_name

from students

where st_name like'__燕%'

3 select st_name,len(st_name) as名字长度

from students

where sex='男'

4 select min(r_fenshu) as最低分数

from teachers t inner join results r on t.t_id=r.r_tid

where t_lesson='数学'--这个是不考虑成绩中有null值的

5 select s.st_id as学生编号,r_fenshu as分数,r_tid as课目号

from students s inner join results r on s.st_id=r.r_stid

where s.sex='女'

--如果还要课目的名称的话请用下面的

select s.st_id as学生编号,r.r_fenshu as分数,r.r_tid as课目号,t.t_lesson as课目名称

from students s inner join results r on s.st_id=r.r_stid

inner join teachers t on r.r_tid= t.t_id

where s.sex='女'

6 select avg(r.r_fenshu)

from results r inner join teachers t on r.r_tid= t.t_id

where t.t_lesson='英语'

7.select*

from students s inner join results r on s.st_id=r.r_stid

inner join teachers t on r.r_tid= t.t_id

where s.st_id in(select top 2 st_id from students order by st_id desc)

order by s.st_id desc

8 select sum(r.r_fenshu) as总分

from results r inner join students s on r.r_stid=s.st_id

where s.st_name='王楠'

9.select distinct s.st_id,s.st_name

from students s inner join results r on s.st_id= r.r_stid

where st_id not in(select r_stid from results where r_fenshu<60) and st_id not in(select r_stid from results where r_fenshu>=90)

10 update results

set r_fenshu= r_fenshu+ 10

--如果分数不可能大于100请用这句 set r_fenshu= case when r_fenshu+ 10<=100 then r_fenshu+ 10 else 100 end

where r_stid in(select st_id from students where sex='女')

1进阶题

select t.t_name,count(*)

from students s,teachers t,results r

where r.r_tid= t.t_id

and s.st_id=r.r_stid

and r.r_fenshu>= 60

and t.t_id in(select t_id from teachers where t_lesson='数学')

--and t_lesson='数学'

group by t.t_name

2

select top 1 sum(r_fenshu) as总分,t.t_lesson,t_id,t_name

from results r,teachers t

where r.r_tid= t.t_id

group by t.t_lesson,t_id,t_name

order by总分 desc

3. delete from results where r_stid in(select r_stid from results group by r_stid having count(r_tid)= 1)

1选做题

select d.name from sysobjects d where d.xtype='U'

2.select top 5* from students order by newid()

SQL 数据库问题,请大神举个例子

、数据库中的主数据文件一定属于主文件组吗?

答:是;因为所有数据库都至少包含一个主文件组,所有系统表都分配在主文件组中,所以一定属于主文件组。

2、数据文件和日志文件可以在同一个文件组吗?为什么?

答:不可以;因为主数据文件存在于主文件组,日志文件不属于任何文件组。

3、删除了数据库,其数据文件和日志文件是否已经删除?

答:是的,全部已删除;

4、TRUNCATE TABLE:删除内容、释放空间但不删除定义。

通过释放存储表数据所用的数据页来删除数据,并且只在事务日志中记录页的释放。

(自增长列重新开始计算)

DELETE TABLE:删除内容不删除定义,不释放空间。

每次删除一行,并在事务日志中为所删除的每行记录一项。(所以delete以后的数据有办法可以恢复的;自增长列接着之前的递增)

DROP TABLE:删除内容和定义,释放空间。

理论知识不一定靠谱,关键自己要实践。

SQL数据库练习题

1. SQL Server 2000是典型的关系型数据库产品。( 1)

2.在一台计算机上可以同时运行多个版本的SQL Server。( 1)

3.在SQL Server中日志文件是维护数据库完整性的重要工具。( 0)

4.在定义数据表时,定义某列为标识列的关键字是Identity。( 1)

5.浮点数据类型的优点是能够存储范围非常大的数字,但容易发生误差。( 0)

6.数据库完整性的目的是为了防止错误信息输入和输出。( 0)

7.在Update语句中,一次可以更新多个表。( 0)

8.尽量使用Select*,可以加快查询速度。( 0)

9.在SQL Server 2000中表示注释可以用类似C语言的/*...*/和//。( 0)

10.在SQL Server中,RTRIM函数删除字符串右边的空白字符。( 1)

11.一个表只能有一个聚集索引(簇索引)。( 1)

12. SQL查询语言中,如果没有指定排序方式,则默认是升序方式。( 1)

13.在SQL Server 2000中ntext类型的字段不能进行排序操作。( 0)

14.在SQL Server 2000中bit类型的字段不能建立索引。( 1)

15.在被定义为唯一索引的列上的数据不能有重复的值。( 1)

16.在被定义为唯一索引的列上的数据不允许空。( 0可以的但是只能有一个null值)

17.在SQL Server中,每张表都应该建立一个索引,以提高查询速度。( 0)

18.视图在SQL Server中是一张虚拟表。( 1)

19.当一个视图由2个以上基本表构成时,不能进行删除视图中的数据。( 0)

20.在SQL Server中,触发器是一种特殊的存储过程。( 1)

21.由于存储过程是解释执行,所以每次执行时都要检查是否有语法错误。( 0)

22.可以在用户正在使用的数据库上执行数据库恢复操作。( 0)

1表示正确

如果你还想了解更多这方面的信息,记得收藏关注本站。

php用什么软件来编程?php在线编程php是什么意思中文 python中文叫啥