how to compare the values of same table(say for eg: Order table) each and every time the record get inserted , if the record with same values get inserted already in same table i should not insert the new record with same values. how to do that exactly in sql server 2008
+1
A:
If exists(select * from Order where key_column=@some_value)
print 'data already exists'
else
Insert into Order(columns) values (@some_value,...)
Madhivanan
2010-06-10 12:41:49
+1
A:
I'd suggest adding a unique index on the key columns...
ALTER TABLE mytable ADD UNIQUE INDEX myindex (keycolumn1, keycolumn2, ...);
That'd make it impossible to insert a duplicate by accident.
Brian Hooper
2010-06-10 13:13:49