There is no quick way to do this in script, at best you can automate it with the following script that essentially takes your new table schema (with your new column at the desired location), inserts all data from old into new, drops the old table and then uses a stored procedure to rename the new table to old.
create table [NewTable]
(
[old_column_1] int
,[new_column_1] varchar(max) -- new col at location
,[old_column_2] int
);
insert into [NewTable] ( [old_column_1], [old_column_2] )
select [old_column_1], [old_column_2] from [OldTable] (nolock);
drop table [OldTable];
sp_rename '[NewTable]', '[OldTable]';
As others have correctly pointed out though, the position of your columns makes NO difference whatsoever to the database, but there is a human desire to achieve this for various personal reasons and so you have a few options. You can either:
- Use the script above to handle the process.
- Allow the appending of your column to the end of the table and control the order in your query.
- Basically an extension to option 2, use a view to control the order in your presentation.
- Use the GUI in SQL Server Management Studio - you can drag and drop your column to the desired location when displaying your table as a grid.