Jump to content
galili

mysqli rename table column

Recommended Posts

Posted (edited)

Folks, whats wrong with this statement on mysqli

 

$sql = "ALTER TABLE bethany RENAME COLUMN `SALE PRICE` TO `saleprice`";

$mysqli->query($sql);
 

 

Edited by galili

Share this post


Link to post
Share on other sites

Quite a lot.

Assuming it is currently defined as

`SALE PRICE` DECIMAL(12, 2) NOT NULL DEFAULT 0

then you need

ALTER TABLE bethany CHANGE COLUMN `SALE PRICE` saleprice DECIMAL(12, 2) NOT NULL DEFAULT 0

 

  • Thanks 1

Share this post


Link to post
Share on other sites

RENAME COLUMN requires MySQL 8.0 so apparently you don't have that.

Share this post


Link to post
Share on other sites
Posted (edited)

OP, Why are you writing Php code for what should be a onetime DB alteration? The command line, Phpmyadmin or some other GUI that works directly on the DB makes much more sense.

Edited by benanamen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.