SQL Server Insert
-
Hi I want to insert into a table information and if the value exists it shouldn't insert but also not throw an error message. Is there any option to the insert statement ? It is in SQL Server. Thanks, Clint
BEGIN TRANSACTION
IF NOT EXISTS (SELECT * FROM SomeTable WHERE SomeColumn = @SomeValue)
BEGIN
INSERT ....
END
END TRANSACTION
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
BEGIN TRANSACTION
IF NOT EXISTS (SELECT * FROM SomeTable WHERE SomeColumn = @SomeValue)
BEGIN
INSERT ....
END
END TRANSACTION
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Yes, but you'll have to catch the exception. The overhead for the exception is probably greater than the overhead for passing over the table twice in a single operation.
Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog
-
Hi I want to insert into a table information and if the value exists it shouldn't insert but also not throw an error message. Is there any option to the insert statement ? It is in SQL Server. Thanks, Clint
Are you doing from Sql Server itself orfrom a client application? If it's the case wich is the programming language you are using? Marc.
... she said you are the perfect stranger she said baby let's keep it like this... Dire Straits