Preventing Duplicates

thanks for all the replies on previous threads.

One thing. I am trying to first delete and then prevent duplicates in my customers table. Specifically their email address field.

As for deleting I have found this which seemed helpful but I have an extraordinary amount of entries and am afraid I wont get the desired results.

http://www.databasejournal.com/features/mssql/article.php/1438651

As for preventing duplicates Ive had similar luck. I tried playing with the properties of the table particularly the IK PK Indexes and constraints for email field and CustomerID index field but my application somehow manages to add duplicate email entries anyway.

Any and all posts are welcome. I am sure this is a fairly common task. however im about a only few months into sql so all help is really appreciated.

thanks
 
Not sure how your adding your customers but handel it there that way dups will never happen.

declare @CustEmail varchar(50)

insert into DATABASE (cols)
values (vals)
where dbCol_CustEmail <> @CustEmail

or you can use

if not exist (select dbCol_CustEmail from DATABASE where dbCol_CustEmail <> @CustEmail)
begin
insert into DB ()
values ()
end

both check if the email exists if it does then it doesnt add
 
Back
Top