question

mahi222 avatar image
mahi222 asked

Validations before insert/update the data

Is there a way to check whether data exists in a table before I INSERT data into the table? I need to check whether the same data already exists. If it does exist then I need an error raised. If not, then INSERT. Please help me, its urgent.
insertexistsunique-constraint
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

GPO avatar image GPO commented ·
Does the table have a primary key or unique constraint (or any other constraints for that matter)? Do you know how to script out the DDL (the CREATE TABLE sql)?
0 Likes 0 ·

1 Answer

·
vinaygr24 avatar image
vinaygr24 answered
There are various methods to achieve this One such method:- If exists (select * from table where condition) begin raiseerror () --- get the proper syntax end else begin insert into table values... end
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.