将值复制到新表并从旧表中删除值
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 表。然后其他值如 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 非常感谢你们对我的帮助。最后我想出了这个触发器,但仍然出现错误。
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
this trigger is not working.please somebody show me the mistake....
when insert a row to messagein table it should copy the value of sender field and copy it to the new_message table.then other values like cusID,CusName,.. should be retrieve from the customer table. please some one help me.
Update:
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 and @TudorConstantin Thank you very much for help me. finally i came up with this trigger but still getting errors.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您至少有一个语法错误:
应该是:
另外,插入应该是:
You have at least one syntax error:
Should be:
Also, the INSERT should be: