...

View Full Version : Changing a field data type



FlashDance
10-30-2011, 04:20 PM
Hi gents,

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)?

doomed2020
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";

FlashDance
10-31-2011, 04:00 AM
Thanks doomed2020, and welcome to the forums!

FlashDance
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?

Old Pedant
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), ....

FlashDance
10-31-2011, 10:18 AM
I see, yes it makes sense.

Thanks for your help, Old Pedant.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum