Insert Oracle column after an existing column

Asked

Viewed 4,240 times

0

I need help. I have the table USUARIO, where I have the columns LOGIN, SENHA but need to include the column called DATACRIACAO, but I would like to know how to insert this column DATACRIACAO after the column LOGIN, I’m working with the Oracle 11g.

1 answer

0


To add the column dating on the table user

ALTER TABLE usuario 
ADD (datacriacao date)

However it is not indicated to change the sequence of the columns as you want, here the reason is explained

  • This command by default when inserting the column at the last position, however you need to insert it after the first existing column.

  • In case I already have entered data, I would not have a way to do via command, I know that in mysql if using the command AFTER + {COLUMN} it insert after the column informed in the after, in oracle has nothing like ?

  • I changed my answer with an interesting information that I found concerning changing the sequence of columns after already having data inserted in the table

  • Do an Insert script (a program like sql Developer does automatico) , drop the table , recreate the table with the correct positions , runs the Insert script , but in my opinion a lot of work for nothing

  • I believe there is no need as you commented @Motta because what will determine the return he will get is the Select what he does. If instead of Select * it determine the order of the columns Select login, datacriacao, senha from usuario the result comes out in the order he wants. What do you think?

  • It helped a lot this article, thanks R.santos, gave me a clear in what I need to do.

  • Like I said I can do it but I don’t think it speaks for effort.

Show 2 more comments

Browser other questions tagged

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