Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drop column failed
Message
De
09/03/2011 16:35:50
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01503074
Message ID:
01503101
Vues:
24
Can the following be a factor?

When I create the field, I create it with the DEFAULT WITH VALUES syntax. But, when I need to enlarge its column, I am creating a temporary field without those clauses because I do an update to replace all the fields of the temporary fields with the original field values and renaming it after.
   IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTable' AND COLUMN_NAME = 'FirstName')
      BEGIN
         SET @Command = N'ALTER TABLE [MyTable] ADD [FirstName] char(25) DEFAULT '''' WITH VALUES'
         EXEC sp_executesql @Command
      END
      ELSE
      BEGIN
         SET @Command = N'ALTER TABLE [MyTable] ADD [FirstName-Temporary] char(25)'
         EXEC sp_executesql @Command
         SET @Command = N'UPDATE [MyTable] SET [FirstName-Temporary]=FirstName'
         EXEC sp_executesql @Command
         SET @Command = N'ALTER TABLE [MyTable] DROP COLUMN [FirstName]'
         EXEC sp_executesql @Command
         EXEC sp_RENAME 'MyTable.FirstName-Temporary', 'FirstName' , 'COLUMN'
      END
This never fails when the field does not exist. But, when it exists, I am using the alternative route in order to avoid a timeout. On some isolated situations, when the table is big, this is when I have a problem.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform