how can I add a new column to more than 500 tables in a database,
I have return all the table name from the DB into a ListBox,
Now I want to loop into that ListBox adding a column to the table,
I actually want to automate a SQl script for adding that column
using this commnd:
ALTER TABLE table
{ [ ALTER COLUMN column_name
{ new_data_type [ ( precision [ , scale ] ) ]
[ COLLATE ]
[ NULL | NOT NULL ]
| {ADD | DROP } ROWGUIDCOL }
]
Andrzej WegierskiPosted Sep 5, 2005, 4:53 AM
string myConnectionString="... ...";
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
myConnection.Open(); foreach(object obj in myListBox.Items)
{
string ins="ALTER TABLE "+obj.ToString()+" ADD(mycolumn ...)";
OleDbCommand myCommand = new OleDbCommand(ins, myConnection);
myCommand.ExecuteNonQuery();
}
myConnection.Close();
I used OleDb, but fill free to use any one. Not tested. See help.