Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object already exist
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01251908
Message ID:
01252247
Vues:
16
John,

In addition to what Sergey said, you should always create temp table using the CREATE TABLE command then INSERT the records into it. When you dynamically create tables using the SELECT...INTO command, it locks the master db while the entire select statement is being created which can cause problems if it takes a while, ie, users cannot create connections, etc.
...

CREATE TABLE #mytable
   (column1   type
    ....            )

IF condition = 'A'
   INSERT INTO #mytable SELECT * FROM inserted
ELSE 
   INSERT INTO #mytable SELECT * FROM inserted WHERE abc = 'A'
...
Kurt


>Hi,
>I have trigger code as below. SQL Server complaint "There is already an object named "#mytable" in the database. But I already restart the server.
>
>
CREATE PROCE myTrigger ON mytable FOR INSERT
>AS
>BEGIN
>  IF condition = 'A'
>    SELECT * INTO #mytable FROM inserted
>  ELSE
>    SELECT * INTO #mytable FROM inserted WHERE abc = 'A'
>END
>
>If I renamed one of them, the error will be gone.
>
>Please advice.
>
>Thank you
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform