I want to know which is the best route to take when verifying if record exists before entering in another record in the database or table.
Do I let the stored procedure handle whether or not record exists or do I handle in code?
Which is the most effective way to this?
Loading

ArshadRank #2,492 · 564 reputationPosted Jan 12, 2012, 11:53 PM EST
If you going to check at the code level, then you might have to hit the database twice to insert a record. but if you keep that logic inside the proc then it will be a single hit and easy. so as per me you can keep the EXISTS logic inside the proc only.
Regards,
Arshad
David SmithRank #999 · 2K reputationPosted Jan 13, 2012, 7:19 AM EST
prc_AddIIcca
(
IN Color VARCHAR (50),
IN Food VARCHAR (50)
)
BEGIN
INSERT INTO iicca
(
Color,
Food
)
VALUES
(
Color,
Food
) ;
END
ArshadRank #2,492 · 564 reputationPosted Jan 14, 2012, 5:17 AM EST
you can write some thing like below inside the proc.
IF NOT EXISTS(Select ColumnName from table Where ColumnName==@InputParameter)
BEGIN
--INSERT LOGIC HERE
END
Regards,
Arshad
David SmithRank #999 · 2K reputationPosted Jan 14, 2012, 9:01 AM EST