Jump to content
galili

mysqli rename table column

Recommended Posts

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

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.