If ALTER COLUMN is not working.
It is not true that a variable column fails because it cannot do the desired conversion. In this case, the solution is to create a table of dummy tables, TableName_tmp, copy the data using a specialized conversion to the massive Insert command, delete the original table and rename the tmp table to the original table name. You will have to drop and recreate the foreign key constraints, and for performance, you probably want to create the keys after populating the tmp table.
Sounds a lot of work? This is actually not the case.
If you use SQL Server, you can make SQL Server Management Studio for you!
Raise the structure of the tables (right-click on the table and select "Change") and make all your changes (if the column transformation is illegal, just add a new column - you will close it in an instant). Then right-click the background in the Modify window and select Generate Change Script. In the window that appears, you can copy the script change to the clipboard.
Cancel the modification (in the end, you will want to check your script), and then paste the script into a new request window. Modify if necessary (for example, add your conversion by removing the field from the tmp table declaration), and now you have the script needed for the conversion.
Mark Brittingham Jan 03 '09 at 13:54 2009-01-03 13:54
source share