数据库三级考试的随笔3.0

1 select name,grade,评价=
2 case 
3 when grade >90 then '优秀'
4 when grade between 80 and 90 then '中等'
5 when grade <80 then '垃圾'
6 end
7 from student

这个就是运行结果

1 select name,sex into 性别表格
2 from student

这个是将查询结果保存到新表;

 这个是union 链接

1 select name
2 from student
3 union all
4 select sex
5 from student

 公用表表达式:

with 公用表表名 (表的列名字,,,,) as (

select 一系列玩意儿

//到这里就是你的公用表创建完毕;

1 create function dbo.CubicVolume  //这个地方是函数的名字;
2     ( @CubeLength int,@CubeWidth int,@CubeHeight int) //三个参数,据说这个是可以使用2100个参数
3 returns int  //返回值返回一个int 型
4 as
5 begin 
6 return (@CubeLength *@CubeWidth*@CubeHeight)
7 end;

注意这个上面的代码是只能运行一次,就是这个批处理文件就是只执行一次

ATTENTION Fuck 。we must use the " @ "and attached to the name .else we can't get the true declare function elements;

nest is the code

1 create trigger yes
2     on student for insert
3 as 
4     IF exists (select * from inserted a
5                 where a.grade > 90)
6     begin 
7         print '你们班走运了,来了个厉害的家伙'
8     end

nest is the result 

 

 

 1 declare @cn nchar(10),@grade int 
 2 /*
 3 declare Cname_cursor1 scroll cursor for  
 4 /*
 5                 这个指定为 Scroll 的游标则变成了 支持所有的提取选项:
 6                 FIRST LAST PRIOR NEXT RELATIVE ABSOLUTE 
 7                 PRIOR : 当前行前面的数据行
 8                 ABSOLUTE这个是指的当前行的第几行;其实 absolue 1 指的就是第一行;absolute 2 指的就是朱曦月
 9                 RELATIVE 这个就是有相对性了
10 */
11     select name,grade from student
12     where sex='g'
13 */
14 
15 open Cname_cursor1 
16 fetch next from Cname_cursor1 into @cn,@grade
17 while @@FETCH_STATUS = 0
18 begin
19     print '姓名   '+ @cn+',分数是这么多:'+ cast(@grade as char(10))
20     fetch next from Cname_cursor1 into @cn, @grade  /*保存都临时变量之中去*/
21 end
22 close Cname_cursor1
23 ;
24 open Cname_cursor1 
25 /*while @@FETCH_STATUS =0
26 */
27 
28 fetch  absolute 4  from Cname_cursor1
29 fetch  prior  from Cname_cursor1
30 fetch  prior  from Cname_cursor1
31 fetch  prior  from Cname_cursor1
32 close Cname_cursor1
原文地址:https://www.cnblogs.com/shewhen/p/11412596.html