SQL Server - How to insert a record and make sure it is unique

前端 未结 7 1480
时光说笑
时光说笑 2020-12-08 02:45

I\'m trying to figure out the best way to insert a record into a single table but only if the item doesn\'t already exist. The KEY in this case is an NVARCHAR(400) field. Fo

相关标签:
7条回答
  • 2020-12-08 03:41

    while unique constraint is certaily one way to go you can also use this for your insert logic: http://www.sqlteam.com/article/application-locks-or-mutexes-in-sql-server-2005

    basicaly you don't put any locks on the table below thus not worrying about the reads while your existance checks will be performed ok.

    it's a mutex in sql code.

    0 讨论(0)
提交回复
热议问题