首页 >数据库 >mysql教程 >SQLServer 2008 新增T-SQL 简写语法

SQLServer 2008 新增T-SQL 简写语法

WBOY
WBOY原创
2016-06-07 18:04:391174浏览

SQLServer 2008 新增T-SQL 简写语法

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)
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn