Scripting Schema Changes

  • I am going to script some schema changes to a couple of tables. However, I would like some newly added fields to be adjacent to some related columns instead of appended to the end of the column list. I don't see a way to do this in code. Do any of you know how to do this without creating a temp table with the desired column order and transferring data into the temp table?

    John R. Laflin


    I Only Work Here......

  • There is no other way unless you write to a temp, drop and re create the table with the desire columns order and then re insert from the temp.

    But, if it is a problem you can create a view with the right order or change your select statement

  • Probably the easiest way is to go into "Design Table" in EM for the tables that you want to move columns around, and then used CUT/PASTE to reposition the column. When you save your changes, EM will write those scripts to copy the data, drop the table, and the replace the data. Save you from writing those data migration scripts.

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • I do what Greg does, use EM to generate the script--but only generate. I then tweak that script as necessary (particularly if new columns need to be assigned any value other than NULL), and make that the migration script. They key thing being, script it, then you can use it over and over and over.

    Ugly, but functional.

    Philip

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

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