SQL Server 2008 新增T-SQL 的正确简写语法


  本文标签:SQL Server 2008

  我们今天主要和大家一起分享的是SQL Server 2008 新增T-SQL 的正确简写语法,如果你对其SQL Server 2008 数据库的新增T-SQL 的正确简写语法有兴趣了解的话,你就可以对其进行点击阅读了  。

  

  1.定义变量时可以直接赋值

  

  

  1. DECLARE @Id int = 5 

  2.Insert 语句可以一次插入多行数据

  1. INSERT INTO StateList VALUES(@Id, WA), (@Id + 1, FL), (@Id + 2, NY) 

  3.支持+=操作符

  1. SET StateId += 1 

  完整示例如下:

  1. view plaincopy to clipboardprint?CREATE TABLE StateList(StateId int, StateName char(2))   
  2. GO -- Declare variable and assign a value in a single statement DECLARE @Id int 
  3. 5 -- Insert multiple rows in a single statement with IDs 5, 6, and 7 INSERT INTO   
  4. StateList VALUES(@Id, WA), (@Id + 1, FL), (@Id + 2, NY) -- Use compound   
  5. assignment operator to increment ID values to 6, 7, and 8 UPDATE StateList SET   
  6. StateId += 1 -- View the results SELECT * FROM StateList CREATE TABLE StateList(StateId int, StateName char(2))  
  7. GO  
  8. -- Declare variable and assign a value in a single statement  
  9. DECLARE @Id int = 5 
  10. -- Insert multiple rows in a single statement with IDs 5, 6, and 7  
  11. INSERT INTO StateList VALUES(@Id, WA), (@Id + 1, FL), (@Id + 2, NY)  
  12. -- Use compound assignment operator to increment ID values to 6, 7, and 8  
  13. UPDATE StateList  
  14. SET StateId += 1  
  15. -- View the results  

  SELECT * FROM StateList 结果集为:

  

  1. StateId StateName  
  2. 6 WA  
  3. 7 FL  
  4. 8 NY  
  5. (3 row(s) affected)  

  

  以上的相关内容就是对SQL Server 2008 新增T-SQL 简写语法的介绍,望你能有所收获  。