Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Added multiple columns from VFP app
Message
De
10/09/2019 01:32:30
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
01670715
Message ID:
01670721
Vues:
60
Should work, but you need to program the alter dynamically depending on # and names of missing columns plus dynamic check.
Often not worth the effort, as such changes should not happen often - KISS and a walk to coffee machine during runtime sufficient for most tables...

>Hi,
>
>I have a code in my VFP application that allows checking if a column exists in a table of a SQL Server database and then add it. The segment of the code that I execute from VFP is below:
>
>
>TEXT TO cSqlCommand TEXTMERGE NOSHOW
>	IF NOT exists (select COLUMN_NAME from INFORMATION_SCHEMA.columns where table_name = '<<tcTableName>>' and column_name = '<<tcFieldName>>' ) 
>		BEGIN
>			alter table <<tcTableName>> add <<tcFieldName>> <<tcFieldType>> null 
>	        SELECT CAST(1 AS bit) AS col_added
>	    END    
>	ELSE 
>		SELECT CAST(0 AS bit) AS col_added
>ENDTEXT
>
>
>The above works fine for one column.
>
>Now I now I need to add more than one column to a table. I could run the above code, with different values of the field name (tcFieldName) and I am sure it will work. But the table is fairly large - almost a million records. So, I am thinking that the above code executed more than one time will take longer (I don't really know how much longer though).
>
>I am thinking that it would be nice to add more than one column in one process. Is it possible? Can I "string" multiple "ALTER TABLE ... ADD " into one command?
>
>TIA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform