1.定義變量時可以直接指派
DECLARE @Id int = 5
2.Insert 語句可以一次插入多行資料
INSERT INTO StateList VALUES(@Id, 'WA'), (@Id + 1, 'FL'), (@Id + 2, 'NY')
3.支援+=操作符
SET StateId += 1
完整示例如下:
view plaincopy to clipboardprint?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 CREATE TABLE StateList(StateId int, StateName char(2))
GO
-- Declare variable and assign a value in a single statement
-- Insert multiple rows in a single statement with IDs 5, 6, and 7
-- Use compound assignment operator to increment ID values to 6, 7, and 8
UPDATE StateList
-- View the results
SELECT * FROM StateList 結果集為:
StateId StateName
------- ---------
6 WA
7 FL
8 NY
(3 row(s) affected)
本文轉自94cool部落格園部落格,原文連結:http://www.cnblogs.com/94cool/archive/2010/03/05/1678886.html,如需轉載請自行聯系原作者