0

So far I am doing it this way:

"ALTER TABLE `database_name`.`table_name` CHANGE 
`old_column_name` `new_column_name` column_type_now"

But this is problematic if the column had not NULL default values or was a key since those things are discarded when the column is renamed.

How I can deal with this issue?

MATH000
  • 1,043
  • 3
  • 13
  • 24
  • 1
    Possible duplicate of [Renaming foreign-key columns in MySQL](http://stackoverflow.com/questions/2014498/renaming-foreign-key-columns-in-mysql) – Mike G Apr 28 '16 at 17:00
  • Why is this question tagged with vb.net? – Jeroen Apr 28 '16 at 22:40

2 Answers2

0

try:

ALTER TABLE `database_name`.`table_name` CHANGE 
`old_column_name` `NEW Column Name` varchar(255) DEFAULT NOT NULL

Replace Varchar with the type of column you're making.

You can also just make it

`DEFAULT NULL` 

If you prefer it to be null.

Did that work?

Max Uland
  • 87
  • 10
  • Oh im sorry. The only thing I would know other than that would be to just make a new table and import the data but that is time consuming. and not very scalable. – Max Uland Apr 28 '16 at 17:25
0

try this:

ALTER TABLE "table_name" CHANGE "old_column_name" "new_column_name" DATATYPE;

FOR ORACLE:

ALTER TABLE "table_name" RENAME COLUMN "old_column_name" TO "new_column_name";
Michael
  • 588
  • 11
  • 19