Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing adding field
Message
De
09/03/2011 10:39:32
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01502961
Message ID:
01503034
Vues:
41
>Generate this script dynamically, e.g.
>
>declare @FieldsToAdd table (FieldName sysname, FieldExtra varchar(800)) -- assuming you only adding fields and never changing type, size, etc.
>declare @Script nvarchar(max)
>select @Script = ''
>select @Scipt = @Script + char(13) + 
> 'ADD ' + quotename(FieldName) + ' ' + FieldExtra from @Fields F
>where not exists (select 1 from Information_Schema.Columns where Table_Name = @TableName and Column_Name = F.FieldName)
>
>set @Script = 'ALTER TABLE ' + quotename(@TableName) + @Script
>
>print @Script -- testing
>
>
>
>from the top of my head.

Thanks, I will check it out.
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
Répondre
Fil
Voir

Click here to load this message in the networking platform