Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing adding field
Message
From
09/03/2011 10:39:32
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01502961
Message ID:
01503034
Views:
40
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform