How can I prevent inserting duplicate data into a SQL Server table?

前端 未结 4 2067
有刺的猬
有刺的猬 2020-12-11 07:01

I have a series of data that need to be written into SQL, what should I do to check the data in SQL to prevent same data inserted into table?

Example data to be inse

4条回答
  •  孤街浪徒
    2020-12-11 07:34

    If you do not want duplicate data, you should consider enforcing that at the DB level with a UNIQUE CONSTRAINT or a UNIQUE INDEX

    SQL Server 2008 also has a MERGE statement you could use to check for matched records. This could be helpful if you want to update an existing record.

提交回复
热议问题