问题描述
嗨!
我有两个具有相同名称和字段的数据库.那里有MessageTransaction表.
我想创建一个触发器,以便每当将数据插入数据库A的表中时
它应该自动将数据插入数据库B.
以下是MessageTransaction表字段.
MessageID数字(10,0)未选中
ChannelNo数字(3,0)已检查
ExtensionNo nvarchar(50)已检查
IPAddress nvarchar(50)已检查
MessageFileName nvarchar(255)已检查
MessageDate日期时间已检查
CallerId nvarchar(50)已检查
InOutFlag int已检查
PlayPath nvarchar(255)已检查
信息字符(25)已检查
Hi!
I have two database with same name and fields. There I have MessageTransaction table.
I want to create such trigger that whenever data inserted into table of database A
it should automatic insert that data into database B.
Following in MessageTransaction table fields.
MessageIDnumeric(10, 0)Unchecked
ChannelNonumeric(3, 0)Checked
ExtensionNonvarchar(50)Checked
IPAddressnvarchar(50)Checked
MessageFileNamenvarchar(255)Checked
MessageDatedatetimeChecked
CallerIdnvarchar(50)Checked
InOutFlagintChecked
PlayPathnvarchar(255)Checked
Informationchar(25)Checked
How to do this ???
推荐答案
ALTER TRIGGER InsertMsgTransaction ON DB1.dbo.MessageTransaction
FOR INSERT
AS
INSERT INTO DB2.dbo.MessageTransaction SELECT * FROM INSERTED
GO
谢谢
Thank you
这篇关于sql server触发自动在其他数据库表上插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!