Sql-server – Need a stored procedure to check and update row when it does not already exists.

sql-server-2008stored-procedures

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.

Best Answer

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