日期:2014-05-18  浏览次数:20510 次

假如我现在插入了N条记录!怎样获得刚插入N条记录的自动编号ID的值
假如我现在插入了N条记录!怎样获得刚插入N条记录的自动编号ID的值

------解决方案--------------------
if exists (select * from dbo.sysobjects where id = object_id(N '[dbo].[A] ') and OBJECTPROPERTY(id, N 'IsUserTable ') = 1)
drop table [dbo].[A]
GO

CREATE TABLE [dbo].[A] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[c1] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[c2] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO

------------------------
create trigger trigger_name on [dbo].[A]
for insert

select id from inserted

----------------------------------
insert a(typename,table2id) select 'aaaa ', 'bb '

---------试试上面的例子