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
David SmithPosted Jan 14, 2012, 2:01 PM
ArshadPosted Jan 14, 2012, 10:17 AM
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 SmithPosted Jan 13, 2012, 12:19 PM
prc_AddIIcca
(
IN Color VARCHAR (50),
IN Food VARCHAR (50)
)
BEGIN
INSERT INTO iicca
(
Color,
Food
)
VALUES
(
Color,
Food
) ;
END
ArshadPosted Jan 13, 2012, 4:53 AM
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