Ask Your Question
3

What is the SQL query method to rearrange the arrangement of columns in a table in SQL Server 2005?

asked 2023-07-07 19:49:21 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-07 20:08:01 +0000

lakamha gravatar image

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;

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-07 19:49:21 +0000

Seen: 9 times

Last updated: Jul 07 '23