Cloning table structure, indexes, foreign keys etc. using SMO

  • Hi,

    I am trying to add a column to a specified position to an existing table using SMO. I couldn't do this with Columns.Add(Column, index) because this was working only if the table is not created already. I found some forum posts that cloning the table, adding the column, dropping existing table and renaming the newly created table is the way to go. I can iterate through all the objects in the table and create copies of them.But is there any simple way to implement this?

    Thanks.

  • If you need to put the new column into a specified position (other than at the end, where it would go in the case of ALTER TABLE ADD COLUMN) then you need to create a new table with the column as you want it, insert the data from the old table into the new, then rename the tables.

    The probability of survival is inversely proportional to the angle of arrival.

  • If this is a manual intervention, then this could be achieved by using Management Studio via modifying the table and insert the column in the intended position...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply