我在插入新行后尝试更新ssn
列。指定我需要将null设置为ssn
列并将该加密值设置为另一列。我的触发器有什么错误或有什么问题吗?
ALTER TRIGGER [dbo].[MemberInsert]
ON [dbo].[Member]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
OPEN SYMMETRIC KEY SSN_Key
DECRYPTION BY CERTIFICATE MyCer;
UPDATE Member
SET [EncryptedSSN] = EncryptByKey(Key_GUID('SSN_Key'), inserted.SSN)
FROM inserted
INNER JOIN dbo.Member On inserted.MemberId = Member.MemberId
UPDATE Member
SET [SSN] = null
FROM inserted
INNER JOIN dbo.Member On inserted.MemberId = Member.MemberId
END
现在添加行没有任何结果。此外,我必须添加使用SqlBulkCopy
插入新行。触发器以这种方式捕获事件是否有问题?
答案 0 :(得分:1)
默认情况下,SqlBulkCopy不会检查触发器,您必须指定选项:SqlBulkCopyOptions
var options = SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.CheckConstraints;
using (var bulkCopy = new SqlBulkCopy(connection, options, transaction))
{
// ...Code...
}