将值复制到新表并从旧表中删除值

发布于 2024-11-10 17:51:39 字数 995 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘羡 2024-11-17 17:51:39

您至少有一个语法错误:

DELETE * FROM messagein 

应该是:

DELETE FROM messagein 

另外,插入应该是:

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)

You have at least one syntax error:

DELETE * FROM messagein 

Should be:

DELETE FROM messagein 

Also, the INSERT should be:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文