SQL Unique Record not column?

前端 未结 4 1753
[愿得一人]
[愿得一人] 2021-01-07 02:14

Is there a way to insert into an SQL database where the whole record is unique? I know you can make primary keys and unique columns, but that is not what I want.

Wha

4条回答
  •  忘掉有多难
    2021-01-07 02:51

    You could do:

    create table #temp (val1 varchar(30), val2 varchar(30))
    
    
    declare @val1 varchar(30),@val2 varchar(30)
    select @val1='josh',@val2='bob'
    
    insert into #temp
    select @val1, @val2
    where not exists (select * from #temp where val1=@val1 and val2=@val2)
    

    Run the bottom half twice and it won't insert the record more then once.

提交回复
热议问题