SQLServer 2008 新增T-SQL 简写语法
更新时间:2009年07月15日 00:37:32 作者:
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)
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)
相关文章
使用Navicat Premium将SQLServer数据导出为sql格式
这篇文章主要介绍了使用Navicat Premium将SQLServer数据导出为sql格式,需要的朋友可以参考下2016-12-12
SQL Server 2008 安装SQLDMO.dll的方法
ASP.NET利用它可以实现在线备份、还原数据库等各种功能2014-05-05
安装sql server 2008时的4个常见错误和解决方法
这篇文章主要介绍了安装sql server 2008时的常见错误和解决方法,本文总结了4个可能问题的问题,并给出了相应的解决方法,需要的朋友可以参考下2014-09-09


最新评论