Adding a constraint to prevent duplicates in SQL Update Trigger
问题 We have a user table, every user has an unique email and username. We try to do this within our code but we want to be sure users are never inserted (or updated) in the database with the same username of email. I've added a BEFORE INSERT Trigger which prevents the insertion of duplicate users. CREATE TRIGGER [dbo].[BeforeUpdateUser] ON [dbo].[Users] INSTEAD OF INSERT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON;