create trigger tr_A_I on A
for insert
as
insert B(id,字段,字段)
select id,字段,字段
from inserted
for insert
as
insert B(id,字段,字段)
select id,字段,字段
from inserted
解决方案 »
- SQL SERVER2005:有列为INT类型且为自增,有问题
- 请教高手 ,group by 难题 需要top 等条件
- sql 查询时 我要先排序 后取出前几行怎么弄? 谢谢各位了
- 请教:两台固定IPMS-SQL SERVER 实时数据同步!
- 关于字段更新的问题!!!
- 创建触发器以后插入数据 提示 "对象名'instered'无效",大虾帮忙看一下
- 怎样改变数据库中float类型的精度?
- ftp://aspxdown:[email protected]/upload/C%23%20by%20pan/网页上《C#完全手册》的打开方式是什么呀,后缀名是.pdf--要安装什么软
- 怎么样实现和上面的记录比较
- 游标+事务处理问题
- 帮我看一下这个SQL为什么老是删除不了?
- 视图不支持case语句怎么办?
如果test2的id时自增长的。下面的触发器中的内容需要修改。
test1的id子增长没有关系。
*/
create table test1 (id_ int identity(1,1),name_ varchar(20))
gocreate table test2 (id_ int ,name_ varchar(20))
go
CREATE TRIGGER tr_test1_i ON [dbo].[test1]
FOR INSERT
AS
set nocount on
insert into test2(id_,name_)
select id_,name_
from inserted
set nocount off
goinsert into test1(name_)
select 'a'select * from test2
/*
id_ name_
---------------------
1 a
*/
set nocount on
SET IDENTITY_INSERT test2 on
insert into test2(id_,name_)
select id_,name_
from inserted
where id_ not in(select id_ from test2)--仅插入test2中没有的id值。
SET IDENTITY_INSERT test2 off
set nocount off