变量

一个@为局部变量,两个@@为全局变量

@@error 最后一句SQL语句的错误编号 错误码

@@identity最后一次插入的标示值符

insert into biao(lie) output inserted.id values(zhi)

select @@identity

@@language

@@version

@@transcount当前事务数  

@@severname本地服务器名字

@@rowcount受上句SQL语句影响的行数

@@max_connections可以创建同时连接的最大数目

先定义,后使用。ADO.Net中给变量起别名加@              任何一个名字会被认为是一个列或者存储过程

定义:declare @变量 类型      declare @name nvarchar(4)

赋值:set @变量 =值  

select @变量=值, @变量=值  

比如

declare @name='张三'

declare @sid =1

select @name= stuName from student where stu_id=@sid   将张三换成查出的name值。

 

流程控制

在sql执行特定的脚本。循环判断,if else

if(条件表达式)   --没有{},用begin end代替。

begin语句end

else

begin语句end

例如

DECLARE @num int
SET @num =2;
IF(@num=2)
begin
select '是二'
end
else
begin
select '不是二'
end
View Code

相关文章:

  • 2022-01-30
  • 2021-11-18
  • 2021-10-11
  • 2022-12-23
  • 2021-10-19
  • 2022-02-02
  • 2022-01-08
  • 2021-04-30
猜你喜欢
  • 2021-08-05
  • 2021-10-13
  • 2021-11-22
  • 2022-12-23
  • 2021-06-07
  • 2021-06-22
  • 2021-11-26
相关资源
相似解决方案