各位大虾,我有三张表相互关联,
table1
   Devicetype(devicetypeid int identity(1,1),decode nvarchar(3))
table2
   Devicelocation(idx int identity(1,1),deviceLocName nvarchar(20))
table3
   Device(DeviceID nvarchar(10),locationLink int,devicetypeID int)
   -- DeviceID是关键字
Table3的LocationLink关联Table2的IDX,Table3的DevicetypeID关连Table1的DevicetypeID我现在两个DB(DB1,DB2的结构完全一样,但数据不一样)
除了发布与订阅,还有什么方法:
我在DB1的device表里增加或者修改一条记录,DB2的Device表也跟着增加或者修改?
不考虑删除的情况,
问题解决,马上揭帖。

解决方案 »

  1.   

    Use DB1
    GO
    Create Trigger Insert_Device On Device
    For Insert
    As
    Insert DB2.dbo.Device Select * From Inserted
    GO
    Create Trigger Insert_Device On Device
    For Update
    As
    Update A Set locationLink =B.locationLink,devicetypeID =B.devicetypeID  From DB2.dbo.Device A Inner Join Inserted B On A.DeviceID =B.DeviceID 
    GO
      

  2.   


    Use DB1
    GO
    Create Trigger Insert_Device On Device
    For Insert
    As
    Insert DB2.dbo.Device Select * From Inserted
    GO
    Create Trigger Update_Device On Device
    For Update
    As
    Update A Set locationLink =B.locationLink,devicetypeID =B.devicetypeID  From DB2.dbo.Device A Inner Join Inserted B On A.DeviceID =B.DeviceID 
    GO
      

  3.   

    如果DB1和DB2在不同的server上,是否需要先建立Linkserver,然后:
    Use DB1
    GO
    Create Trigger Insert_Device On Device
    For Insert
    As
    Insert [192.168.4.2].DB2.[dbo].Device Select * From Inserted
    GO
    Create Trigger Update_Device On Device
    For Update
    As
    Update A Set locationLink =B.locationLink,devicetypeID =B.devicetypeID  From [192.168.4.2].DB2.[dbo]..dbo.Device A Inner Join Inserted B On A.DeviceID =B.DeviceID 
    GO带IP作业?