使用触发器插入更新的列名称 [英] Inserting updated column name using trigger
问题描述
你好专家,我希望能够使用after触发器将已修改的列的名称插入到另一个表中。
hello experts, i want to be able to insert the name of the column that was modified into another table using after triggers.
USE [Test]
GO
/****** Object: Trigger [dbo].[trgUpdate] Script Date: 01/28/2013 13:33:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[trgUpdate] on [dbo].[Tbl_User_Information]
for update
as
declare @EmpID as int;
declare @Field as varchar(50);
declare @Action as varchar(50);
select @EmpID=i.U_ID from inserted i;
if update(FullName)
select @Field= (select c.name from syscolumns c join sysobjects o on o.id=c.id where c.name like '%FullName%');
set @Action='Updated';
insert into Test_Table values(@EmpID,@Field,@Action);
...触发器编译成功但在Tbl_user_information表上更新名为fullName的列后....它返回一个错误,说子查询返回多个值。它可能指向select @ Field =(select ....)语句。我从谷歌获得的一些链接中获得了子查询。我不清楚。
那么我怎样才能将列名插入到上面代码中指定的另一个表(Test_Table)中?任何帮助都会被贬值。
提前致谢。
Minghang
...the trigger compiled successfully but after an update on the the Tbl_user_information table for column named fullName....it returned an error saying the subquery returned multiple values. It''s probably pointing to the select @Field=(select....) statement. i obtained the subquery from some link i got from google. It''s not clear to me.
So how can i just insert the column name into another table (Test_Table) as specified in the code above? Any help will be apreciated.
Thanks in advance.
Minghang
推荐答案
您选择包含的所有字段FullName文本 - 不仅来自特定表,来自所有表!因此,在where子句中添加其他条件,将查询限制为Tbl_User_Information表。
You select all fields that contain the "FullName" text - not only from a specific table, from all tables! So add an other condition to the where clause to restrict the query to the Tbl_User_Information table.
这篇关于使用触发器插入更新的列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!