欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQLServer 2008 新增T-SQL 简写语法

程序员文章站 2023-12-25 16:27:03
1.定义变量时可以直接赋值 declare @id int = 5 2.insert 语句可以一次插入多行数据 insert into statelist values(@...
1.定义变量时可以直接赋值
declare @id int = 5
2.insert 语句可以一次插入多行数据
insert into statelist values(@id, 'wa'), (@id + 1, 'fl'), (@id + 2, 'ny')
3.支持+=操作符
set stateid += 1
完整示例如下:
复制代码 代码如下:

create table statelist(stateid int, statename char(2))
go
-- declare variable and assign a value in a single statement
declare @id int = 5
-- insert multiple rows in a single statement with ids 5, 6, and 7
insert into statelist values(@id, 'wa'), (@id + 1, 'fl'), (@id + 2, 'ny')
-- use compound assignment operator to increment id values to 6, 7, and 8
update statelist
set stateid += 1
-- view the results
select * from statelist

结果集为:

stateid statename
------- ---------
6 wa
7 fl
8 ny

(3 row(s) affected)

上一篇:

下一篇: