CREATE TRIGGER trigg_msg
ON messagein
FOR insert,delete,update AS
IF EXISTS (SELECT * FROM INSERTED)
BEGIN
INSERT INTO new_message (Phone number,CusID,CusName,CusAddress) values ( SELECT ins.sender FROM inserted ins, SELECT cus.CusID FROM customer cus, SELECT cusname FROM customer cus, SELECT cus.cus_phone number FROM customer cus, SELECT cus.Address FROM customer cus)
DELETE * FROM messagein
END
这个触发器不起作用。请有人告诉我错误....
当在messagein表中插入一行时,它应该复制sender字段的值并将其复制到new_message表。然后应该从customer表中检索其他值,如cusID,CusName,..请有人帮助我。
CREATE TRIGGER trigg_msg
ON messagein
FOR insert
IF EXISTS (SELECT * FROM INSERTED)
BEGIN
INSERT INTO new_message(Phone_number,CusID,CusName,CusAddress) values ( SELECT ins.sender FROM inserted ins, SELECT cus.CusID, cus.cusname, cus.cus_phone_number, cus.Address FROM customer cus)
DELETE FROM messagein
@Devart和@TudorConstantin非常感谢你的帮助。最后我想出了这个触发器,但仍然出现错误。
答案 0 :(得分:1)
您至少有一个语法错误:
DELETE * FROM messagein
应该是:
DELETE FROM messagein
此外,INSERT应为:
INSERT INTO new_message (Phone_number,CusID,CusName,CusAddress) values ( SELECT ins.sender FROM inserted ins, SELECT cus.CusID, cus.cusname, cus.cus_phone_number, cus.Address FROM customer cus)