Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The SQL query to rearrange the columns in a table in SQL Server 2005 is as follows:

ALTER TABLE tablename ALTER COLUMN columnname columndatatype AFTER columntomove_after;

In this query, "tablename" refers to the name of your table, "columnname" refers to the name of the column you want to move, "columndatatype" refers to the data type of the column, and "columntomove_after" refers to the name of the column you want to move the first column after.

For example, if you want to move the "dateofbirth" column after the "last_name" column in the "customers" table, you can use the following query:

ALTER TABLE customers ALTER COLUMN dateofbirth datetime AFTER last_name;