码迷,mamicode.com
首页 > 其他好文 > 详细

表变量和临时表

时间:2015-01-09 18:50:33      阅读:306      评论:0      收藏:0      [点我收藏+]

标签:

SET NOCOUNT ON;

DECLARE @TestTable TABLE (
RowID INT IDENTITY PRIMARY KEY CLUSTERED,
Name VARCHAR(9) NOT NULL UNIQUE,
Age TINYINT NULL,
rowguid UNIQUEIDENTIFIER NOT NULL DEFAULT(newid()));

begin tran

INSERT INTO @TestTable (Name, Age) VALUES (‘Roy‘, 25),(‘中国风‘, 21);
rollback tran

SELECT ‘Insert rows‘ as Action, * FROM @TestTable;
/*
Action RowID Name Age rowguid
Insert rows 1 Roy 25 84C4F6CC-3AB3-4D7D-8779-0DCF3414AB61
Insert rows 2 中国风 21 1DB02A77-F20E-4326-A4E4-023CE9F5DEA7
*/
go
if OBJECT_ID(‘Tempdb..#TestTable‘) is not null
drop table #TestTable
CREATE TABLE #TestTable (
RowID INT IDENTITY PRIMARY KEY CLUSTERED,
Name VARCHAR(9) NOT NULL UNIQUE,
Age TINYINT NULL,
rowguid UNIQUEIDENTIFIER NOT NULL DEFAULT(newid()));

begin tran

INSERT INTO #TestTable (Name,Age) VALUES (‘Roy‘, 25),(‘中国风‘, 21);
rollback tran
SELECT ‘Insert rows‘ as Action,* FROM #TestTable
/*
无记录
*/

表变量和临时表

标签:

原文地址:http://www.cnblogs.com/q101301/p/4213763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!