solorez~Z Space

关注数据库,关注MS SQL Server

导航

SQL Server 2008 T-SQL 新增语法功能

SQL 2008增强了不少T-SQL特性,本篇文章简单介绍了这些特性:

一、DECLARE 语句

变量声明时,可以指定默认值。但是TEXT、NTEXT、IMAGE数据类型除外。
例如:

DECLARE @MyName varchar(20)='Solorez'

二、赋值运算符

SQL Server 2008 已经支持赋值运算符,比如" +=, -=, /=, %=, &=, |=, and ^="。

例如:

DECLARE @MyNumber int = 2
SET @MyNumber += @myNumber

三、行值插入(原文为: Row Constructor,译注)

SQL Server 2008 允许一个Insert语句插入多行。

例如:

CREATE TABLE SolorezTable
(ID int, Item varchar(20))
INSERT INTO SolorezTable VALUES
(1, 'Bike'), (2, 'Car'), (3, 'Truck')

四、MERGE 语句

你可以选择性的合并两个表的内容(内容的结构要一致)。

例如:


CREATE TABLE MyTable2
(ID int, Item varchar(20))
INSERT INTO MyTable2 VALUES
(1, 'Bike'), (2, 'Van'), (4, 'Motorcycle')
GO
MERGE MyTable2 AS TargetTable
USING (SELECT ID, Item FROM MyTable)
SourceTable
ON (TargetTable.ID = SourceTable.ID)
WHEN TARGET NOT MATCHED
THEN INSERT VALUES (ID, Item)
WHEN SOURCE NOT MATCHED
THEN UPDATE SET Item = Item;
GO


参考文献:

"New Data Types in SQL Server 2008," InstantDoc ID 97686


"SQL Server 2008 Boosts Build-in Encryption," InstantDoc ID 98080


"Compression in SQL Server 2008," InstantDoc ID 98123


"SQL Server 2008 Business Intelligence Enhancements," InstantDoc ID 98467


"Familiar SQL Server Tools in a New Wrapper," InstantDoc ID 98836




原文来自:SQL Magine
地址:http://www.sqlmag.com/Article/ArticleID/99416/sql_server_99416.html

posted on 2008-10-04 18:13  付博  阅读(1674)  评论(0编辑  收藏  举报