Changing the order of the Sql columns?

2

Good morning

Could you instruct me to change the order of the columns in a table? Example: I have Table IcmsMvaUF in the following order:

I'd like to pass the MvaEmpresa column to the first column on the left side of the MvaClaFiscal column. It is a PK column that already has data load and I would like to do this without losing any data. I already tried to Design , but it does not allow the change.

    
asked by anonymous 25.05.2017 / 16:38

2 answers

6

First, this does not bring any benefit, because the order of the columns is something only visual for us, something "cosmetic", SQL Server does not care about it.

The only way to do this is by recreating the table and this is just what SQL Server Design does. Probably the error that occurred when you try to reorder is because the option to enable table re-creation is disabled.

Remembering that this design ordering is only available from the 2012 version, according to Microsoft documentation ;

Source: link

    
25.05.2017 / 17:05
4

You can change by Design View as long as you disable the Avoid saving changes that require re-creating table option. This option is in Tools > Options > Designers:

After this open the table designer, change the column order by dragging it wherever you want and saving the changes.

Important: Note that this will re-create the column. It will make a temp_table to hold the data, probably.

    
25.05.2017 / 17:08