Transact-SQL

简介: Transact-SQL

Transact-SQL

Transact-SQL语言是SQL语言的增强版

声明局部变量

DECLARE 
{@变量名称[AS]变量类型}

注释方式

单行注释:–

多行注释:/* … */

流程控制语句

IF…ELSE语句

  IF 表达式
  {语句块}
  ELSE
  {语句块}

语句块中包含BEGIN…end语句

CASE语句

CASE 表达式
WHEN...THEN...
[n...]
[else]
end

Select 员工姓名,所任职位,员工职称

Case 所任职位

when ‘经理’ then ‘高级职称’

when ‘主管’ then ‘中级职称’

else ‘其他职称’

end

FROM 员工信息

while语句

while 布尔表达式
{语句块}
[BREAK]
{语句块}
[CONTINUE]
语句块

DECLARE @i int, @num int

Set @i = 1

Set @num = 1

While @i<=10

BEGIN

SET@num=@num*@i
set@i=@i+1

END

PRINT @num

WAITFOR延迟语句

waitfor
{
DELAY time
| TIME time
}

Waitfor delay ’00:00:05’

Exec sp_help

Waitfor time ’21:11:05’

Exac sp_helpdb

GOTO语句

Declare @count int
Set @counter = 1
While @counter <10
BEGIN 
Print @counter 
Set @counter =@counter + 1
If @counter=4 GOTO branch one –jumps to the first branch.
If @counter=5 GOTO branch_two –this will never execute.
End
Branch one:
Print ‘jumping to branch one.’
GOTO Branch_three: --this will prevent branch_two from executing
Branch two:
Print ‘jumping to branch two.’
Branch_three:
Print ‘jumping to branch three.’

**TRY…CATCH错误处理语句

begin try
{语句块}
FND TRY
BEGIN CATCH
{语句块}
end CATCH

Begin try

Declare @num int

Set @num = 1/0

Select @num

End try

Begin catch

Select err_line() as ‘错误行数’

End catch

目录
相关文章
|
SQL 存储 关系型数据库
SQL语句大全,所有的SQL都在这里
SQL语句大全,所有的SQL都在这里
|
存储 SQL 数据库
SQL必知必会(二)
表中的数据都是按行来存储的,所保存的每个记录存储在自己的行内。如果将表想象为网格,网格中垂直的列为表列,水平行为表行。
|
SQL
SQL日常
SQL日常
120 0
|
关系型数据库
xttdbopen.sql
connect / as sysdba; alter database mount;alter database open; exit
759 0
|
SQL 数据库 关系型数据库
SQL
SQL查询优先级() not and or SQL模糊查询 '%a' //以a结尾的数据'a%' //以a开头的数据'%a%' //含有a的数据'_a_' //三位且中间字母是a的'_a' //两位且结尾字母是a的'a_' /.
995 0