我有三个表作为客户,客户日志和地址。我想将由外键(客户表的主键)和地址表中的所有列组成的新行添加到客户日志表中。有人可以纠正这个触发器吗?先谢谢了。
客户栏:
customerId, addressId, name, auto, type, date
客户日志列:
customerId, addressId, street, number, city, country
地址栏:
addressId, street, number, city, country
扳机:
create trigger insertCustomerLog
on customer
for insert
if INSERTED.type = 'B'
begin
INSERT INTO customer-log
SELECT INSERTED.customerId,(SELECT * FROM address AS a WHERE INSERTED.addressId = a.addressId)
end