SQL conditional multiple ODBC connections

  • If I have 100 ODBC clients all submitting the following SQL at the same time how do I know that the SQL inside the conditional only gets executed once. It appear SQL Server is preventing it from happening but was curious how. Or do I need to add something to prevent it from happening.

    IF NOT EXISTS (SELECT name FROM sysobjects WHERE type='U' AND name = 'mytable)

    BEGIN

    CREATE table mytable (task int NOT NULL, first_name varchar(128), last_name varchar(128))

    END

  • Because you're telling the server to only create the table IF NOT EXISTS.

    IF NOT EXISTS is a conditional operation actually your code is 2 conditional expressions and a transaction in between.

    So the optimizer runs not exists 100 times but only 1 create table.

    Alex S

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply