22,209
社区成员
发帖
与我相关
我的任务
分享
insert into a ([user],pass) values('aaa','bbb');
insert into b (id) values (@@IDENTITY)
--建议用触发器
create trigger 触发器名
on 表A
after insert
as
begin
insert into表2(id)
select ID from inserted
end
要注意 你表2 id 字段不能为自增列
drop table t
create table t(
id int identity ,
name varchar(30)
)
set nocount on
insert into t(name) values(100)
select @@IDENTITY
insert into t(name) values(100)
select @@IDENTITY
set nocount off
---------------------------------------
1
---------------------------------------
2
string strsql = "insert into t(name) values(100) ";
strsql += "select @@IDENTITY";
cmd.CommandText = strsql ;
object obj = myComm.ExecuteScalar();