I have got 3 columns in the table, I need to check the email field before insertion of new row, so if the email exist, it should not insert that row. Do I have to go through 2 queries to achieve that, so for instance first check :
Select count(*) FROM PRODUCT WHERE email = @email
AND THEN RUN AN INSERT
Insert INTO PRODUCT (....) VALUES (....)
Or is there any better way to achieve that ,
Any suggestions or advice will be appreciated .
Thanks
You can have an INSERT
statement that checks for the condition, and only inserts something, if it doesn't already exist:
IF NOT EXISTS (SELECT * FROM dbo.Product WHERE email = @email)
INSERT INTO dbo.Product(list of columns)
VALUES(list of values)