View Full Version : Changing a field data type
10-30-2011, 04:20 PM
Is there a way to change a field from a VARCHAR to something else? Say, I wanted to change a field that I set to VARCHAR(100) and want to change it to INT(11)?
10-30-2011, 07:15 PM
ALTER TABLE `user` CHANGE `DoB` `DoB` INT( 11 ) NOT NULL
$sql = "ALTER TABLE `user` CHANGE `DoB` `DoB` INT(11) NOT NULL";
10-31-2011, 04:00 AM
Thanks doomed2020, and welcome to the forums!
10-31-2011, 06:11 AM
I tried using the command like this, but it didn't work.
alter table feedback change id id int(11) not null auto_increment, primary key (id);
Do you know why this happened?
10-31-2011, 07:10 AM
You can't make two changes at once. Your ", primary key (id)" is thus rejected.
The funny thing is, if you had simply coded
alter table feedback change id id int(11) not null auto_increment primary key;
it would work. You do not *HAVE* to use a separate specification when defining a primary key.
Even in CREAT TABLE you can do
CREATE TABLE tbl (
id int auto_increment primary key,
name varchar(100), ....
10-31-2011, 10:18 AM
I see, yes it makes sense.
Thanks for your help, Old Pedant.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.