Click here to Skip to main content
15,878,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to work on a program where two table having an email column now i have to work on to keep email value unique for both tables for insert and for update also
please help
thank in advance
Updated 19-Jun-12 22:05pm

Do you mean that you have two separate tables, each with an email address, which may not be repeated in the other table?
If so, then just check the count of entries in the other table:
SELECT COUNT(email) FROM OtherTable WHERE email=ToBeInsertedEmailAddress
If it's zero, you can do it.

If that isn't what you mean, please explain a bit more clearly!
Share this answer
IF (EXISTS(SELECT email FROM WHERE email = ''))
PRINT 'Email is already there';
      INSERT INTO,name)
      VALUES ('','user2');
Share this answer
hi ,

you can use insert and update trigger to fix this issue bellow links will help you out
Share this answer
While creating the tables make the email column as Unique so that user can't insert same value to that column.
If you want to implement manually than before every insertion or update check that is that value is already present or not.
Share this answer
naren programmers 20-Jun-12 4:26am    
the application which i got there is a user table and employer table both have a email column the field should not be the same as this is an email , i can not convert these table to one table and then apply unique constraint as the application is at its final stage
bhagirathimfs 20-Jun-12 5:10am    
See Solution 4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900