数据每晚由 .Net 服务输入到这个表中,我不习惯更新.我想要一个触发器,上面写着:嘿,我看到您正试图在 SSN 列中插入一些内容...让我们在插入之前对其进行哈希处理. 解决方案 一种方法是使用 INSTEAD OF TRIGGER:创建触发器 dbo.HashSSNON dbo.tablename代替插入作为开始设置无计数;插入 dbo.tablename(FirstName, LastName, SSN)SELECT FirstName, LastName, HASHBYTES('SHA1', SSN)从插入;结尾走I have a table called employees with 3 columns: FirstName, LastName, and SSN.Data is fed into this table nightly by a .Net service, something I'm not comfortable updating.I'd like to have a trigger that says: Hey, I see you're trying to insert something in the SSN column... let's HASH that before it goes in. 解决方案 One way is to use an INSTEAD OF TRIGGER:CREATE TRIGGER dbo.HashSSNON dbo.tablenameINSTEAD OF INSERTASBEGIN SET NOCOUNT ON; INSERT dbo.tablename(FirstName, LastName, SSN) SELECT FirstName, LastName, HASHBYTES('SHA1', SSN) FROM inserted;ENDGO 这篇关于如何在插入之前将触发器写入哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-14 05:42