Link to home
Start Free TrialLog in
Avatar of vijayprabakar
vijayprabakarFlag for India

asked on

Best Approach - Verify if a variable exist in a Database table.

Hi Experts,

I need to verify if a variable exist in a DB table which has around 10,000 records. I have 2 approaches:

1. Query the table with a 'Where' clause.
2. Try to insert the record into the table and catch Unique Key Violation Exception if the record already exists.

Is there any other solution? What is the best approach?

Regards,
Vijay
Avatar of ksivananth
ksivananth
Flag of United States of America image

if yours is the only application manages this and you can afford to load all records into in memory, that would faster to check. if not I would choose option 1 from what you have listed, unique key violation can fail if the field is not defined as unique in DB.
ASKER CERTIFIED SOLUTION
Avatar of Sara bhai
Sara bhai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial