Click here to Skip to main content
15,887,828 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a Work_Details table containing
Work_Name

intigrated
stringvalue
CharValue

Now I need a query that will return something if I give duplicate name.
Means if I give CharValue again it will not insert in the table.
How can I put a check before inserting in to the table?
Posted

You don't need to check before the INSERT.

Make one of the fields a unique key, then when you attempt to INSERT into the database it will fail telling you that that record already exists.
 
Share this answer
 
v3
Comments
sasen903 8-Mar-13 5:54am    
The table should not have any Primary Key.
I just need to return a value(suppose using count()) that will say if the value exists in the table or not.
And i will check using the value
SQL
if not exists ( select * from table  where field=value)
begin
put insert query 
end


and if want to see dublicate row

use

like

select count(*) from table group by (column name ) having count(*)>1

it will all dulicate record
 
Share this answer
 
Comments
sasen903 8-Mar-13 5:56am    
How the Count will return a value if the data is existing in the table or not

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