Take the 2-minute tour ×
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. It's 100% free, no registration required.

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 def@ggg.com 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
4  
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? –  Emmad Kareem Jul 30 '12 at 3:08
add comment

1 Answer

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:

http://www.techrepublic.com/article/defining-sql-server-constraints-with-tsql/6181836

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 http://msdn2.microsoft.com/en-us/library/ms175132.aspx here

share|improve this answer
add comment

Your Answer

 
discard

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.