日期:2014-05-17 浏览次数:20418 次
drop table tb
create table tb
(
id int identity,
col1 varchar(10),
col2 varchar(10),
)
insert into tb
select 'a','b' union all
select 'a','a' union all
select 'b','b'
insert into tb
output inserted.id
select col1,col2 from tb
----------
id
4
5
6
--> 数据库版本:
--> Microsoft SQL Server 2008 (RTM) - 10.0.1600.22
--> 测试数据:tabA
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tabA')
AND type in (N'U'))
DROP TABLE tabA
GO
---->建表
create table tabA([col1] varchar(1),[col2] varchar(2))
insert tabA
select 'a','b' union all
select 'c','f' union all
select 'v','fr'
GO
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'tabB')
AND type in (N'U'))
DROP TABLE tabB
GO
---->建表
create table tabB([col1] varchar(1),[col2] varchar(2))
go
--> 查询结果
declare @t table ([col1] varchar(1),[col2] varchar(2))
insert into tabB(col1,col2)output inserted.col1,inserted.col2 into @t
select col1,col2 from tabA
SELECT * FROM @t
--> 删除表格
--DROP TABLE tabA