使用触发器,我们可以将一个表的相同值插入另一个表. [英] using trigger can we insert the same values of one table to another.
本文介绍了使用触发器,我们可以将一个表的相同值插入另一个表.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过使用触发器将一个表的值插入另一个表.这两个表的列都相同,我想插入值.
I wants to insert the values of one table to another by using trigger. the columns are same for both the tables and i wanna insert values. how would I?
推荐答案
您的问题的答案是是",您可以使用触发器进行操作.为此,您将必须使用插入"触发器.
Code :
The answer to your question is YES, you can do it using trigger. You will have to use the Insert trigger for this.
Code :
CREATE TRIGGER triggerName ON yourSourcetable FOR INSERT
AS
INSERT INTO yourDestinationTable
(col1, col2 , col3)
SELECT
'value1', 'value2', 'value3'
FROM inserted
GO
当您要访问要插入的新记录时,可以使用系统表名称inserted
进行访问.我只用了这张桌子.因此,您可以用表的列替换列的名称.
希望这会有所帮助.
一切顺利.
when you want to access the new record which is being inserted then the same can be accessed using system table name inserted
. I have used this table only. So you can replace the names of the columns by your table''s columns.
Hope this helps.
All the best.
这篇关于使用触发器,我们可以将一个表的相同值插入另一个表.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文