CREATE TRIGGER自动将更新的字段复制到另一个字段 [英] copy an updated field to another field automatically by CREATE TRIGGER
问题描述
我正在使用sql server。
这里有一些字段:column1,column2,...
用户可以访问column1,他可以更新它的内容。
现在我想创建一个触发器来复制column1的新内容自动到第2列。
例如set column2 = column1 AFTER UPDATE(column1)
我已经在桌面上创建了一个触发器。在触发器中我使用下面的代码:
Hi, I''m using sql server.
there''s a table with some fields: column1, column2, ...
the user has access to column1, and he can update it''s content.
Now I want to create a trigger to copy the new content of column1 to column2 automatically.
e.g. set column2 = column1 AFTER UPDATE (column1)
I''ve created a trigger on the table. in the trigger I use the code bellow:
CREATE TRIGGER [dbo].[mytrigger]
ON [dbo].[mytable]
AFTER UPDATE
AS
IF UPDATE(userName)
BEGIN
SET NOCOUNT ON;
-- HERE I SHOULD WRITE A CODE TO COPY NEW DATA OF COLUMN1 TO COLUMN2 !! :-??
END
我应该使用什么代码而不是评论??
我会感激任何帮助。
WHAT code should I use instead of the comment ??
I''ll appreciate any help.
推荐答案
看看这里:
http://stackoverflow.com/questions/741414/insert-update-trigger-how-to-determine-if-insert-or-update [ ^ ]
http://www.sqlteam.com/forums/topic.asp?topic_id= 94688 [ ^ ]
http://msdn.microsoft.com/en-us/library/ ms187326.aspx [ ^ ]
关于触发器的更多信息: http://www.sqlteam.com/article/an-introduction-to-triggers-part-i [ ^ ]
Have a look here:
http://stackoverflow.com/questions/741414/insert-update-trigger-how-to-determine-if-insert-or-update[^]
http://www.sqlteam.com/forums/topic.asp?topic_id=94688[^]
http://msdn.microsoft.com/en-us/library/ms187326.aspx[^]
More about triggers: http://www.sqlteam.com/article/an-introduction-to-triggers-part-i[^]
这篇关于CREATE TRIGGER自动将更新的字段复制到另一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!