Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need a stored procedure that will check and then update the rows (with username & email) except the id (auto incremented with a unique one).

For example, if id = 5 has, the username abc and the email is and the id is unique. Before it updates that row, it has to check the table to see if the username and email already exists. If anybody already has that username and email the table is not updated.

Please provide a stored procedure for this issue.

share|improve this question
You are defining in a very convoluted way a unique constraint on username and email. – Remus Rusanu Jun 27 '12 at 6:17
You need to re-phrase your question to provide business rules for cases of INSERT and cases of UPDATE. Try to write specific rules. After you do this specify what is the problem exactly? – NoChance Jul 30 '12 at 3:08
up vote 0 down vote accepted

without any more information it is difficult to give you the "right :)" answear. but what i can tell you, check:

and ...

When you specify a PRIMARY KEY constraint for a table, the SQL Server Database Engine enforces data uniqueness by creating a unique index for the primary key columns. If a PRIMARY KEY constraint is defined on more than one column, values may be duplicated within one column, but each combination of values from all the columns in the PRIMARY KEY constraint definition must be unique.

See more on here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.