insert时,能不能同步复制自动增长的ID列? 如列ID,Username,ID2ID为自动增长列,insert时,ID2=ID在SQL中可以做到吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 插入完后再update tb set id2 = id 两个都设为自动增长或create trigger trigger_name on tbfor insert as update tb set id2=id from tb join inserted on tb.id=inserted.id declare @t table(ID int identity,Username varchar(10),ID2 as ID*1)insert @t select 'A' insert @t select 'B' select * from @t/*ID Username ID2 ----------- ---------- ----------- 1 A 12 B 2*/ 首先有个问题,两个字段内容一样,那ID2有什么意义,直接不要ID2这样就行select ID,ID ID2,Username如果非要ID21.插入完后再update tb set id2 = id2.在表里建一个insert触发器,触发器内容就是update tb set id2 = id update tb set id2 = idwhere id=@@identity 求一 SQL语句 ,行转列 可以在订阅表上建触发器吗? SQL访问问题 高手指点一下哦! 两个数据集联合的问题!!!!!!!!!!!!!!!!!!!!!!!!!!! 急救,,, 一个简单的sql语句怎么写。 字段类型问题 MSSQL server 的 Function 是个烂东西 知道一台winnt+oracle服务器后,怎样才能搞定她地sid ?? sqlserver2008安装失败,求解啊!!! 《网络成瘾临床诊断标准》 存储过程语句-帮我具体解释这段小代码
for insert
as
update tb set id2=id
from tb join inserted on tb.id=inserted.id
insert @t select 'A'
insert @t select 'B'
select * from @t
/*ID Username ID2
----------- ---------- -----------
1 A 1
2 B 2*/
这样就行
select ID,ID ID2,Username如果非要ID2
1.插入完后再update tb set id2 = id
2.在表里建一个insert触发器,触发器内容就是update tb set id2 = id
where id=@@identity