We commonly encounter a scenario where we have to check if a data is already there in table before going for any insertions. So here is a quick query for this purpose
please note that i wrote this query keeping Sql Server in mind.
IF NOT EXISTS ( SELECT TOP 1 [NAME] FROM myTable WHERE [Name] = 'check_name' )
BEGIN
INSERT INTO myTable
([Name]
,[Description]
)
VALUES
('check_name'
,'test'
)
END
No comments:
Post a Comment