用触发器实现两表数据同步如何做啊? 急!!!
用触发器实现两表数据同步如何做啊? 急!!!
比如插入,更新,删除时希望主表和从表数据一致.这个触发器该怎么写呀.
use dearsky
create table tb4 (
userid int primary key not null,
productid int,
constraint fk_tb4_tb5 foreign key (productid) references tb5(productid)
)
create table tb5(
productid int primary key not null,
productname varchar(30)
)
------解决方案----------------------删除触发器
create trigger td_tb4 on tb4
for delete
as
delete from tb5 where productid in (select productid from deleted)
------解决方案--------------------哪个是主表,哪个是从表,你需要更新哪些数据?
------解决方案--------------------关联字段是?