Order change of Sql columns?

Asked

Viewed 2,067 times

2

Good morning

Could you instruct me to change the order of the columns in a table? Example: I have the Table IcmsMvaUF in the following order: inserir a descrição da imagem aqui

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

  • You could post the Create code from the table?

  • Igor can not see the gain that will have with this. Could explain where you want to go with this?

  • @Marconi is by default the other table that has with PK the company. As I did not pay attention to this and started creating the column, I was questioned by a co-worker

  • 2

    @Igorcarreiro honestly this has no influence on your table and your queries

  • 1

    And if you create a time table based on a select of this table by inverting the columns, then delete this and do the procedure again for the correct table name?

  • @Jefersonalmeida is what I think.

  • @Jefersonalmeida Yes, does not disturb anything at all, it would be even the standardization of the other created that has with PK the company

Show 2 more comments

2 answers

6

Firstly, 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 that is precisely what SQL Server Design does. Probably, the error that occurred when you try to reorder is why it should be disabled to enable table recreation.

Recalling that this ordering by Design is only available from the 2012 version, according to microsoft documentation;

Source:https://stackoverflow.com/a/1605167/4166090

5

You can switch to Design View as long as you turn off the option "Avoid saving changes that require table recreation". This option is in Tools > Options > Designers:

inserir a descrição da imagem aqui

After this open the table designer, change the order of the column by dragging it to where you want and save the changes.

Important: Note that this will recreate the column. It will make a temp_table to keep the data, probably.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.