easy mysql question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

easy mysql question

Post by boo_lolly »

i have a database table, one of the columns is set to CHAR(20)... how do i change it to CHAR(30) using the mysql command line?
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

try this

Code: Select all

ALTER TABLE `table_name` CHANGE `field_name` `field_name` INT( 30 ) NOT NULL AUTO_INCREMENT 
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

thanks obadiah! what is the purpose of AUTO_INCREMENT? what would the effect be if i didn't place that in the command?
User avatar
Obadiah
Forum Regular
Posts: 580
Joined: Mon Jul 31, 2006 9:13 am
Location: Ashland, KY
Contact:

Post by Obadiah »

sorry...i tested it on one of my databases first the field i tested it on had an auto increment...did you add the autoincrement to it as well...ill help you remove it if so

Code: Select all

ALTER TABLE `table_name` CHANGE `field_name` `field_name` VARCHAR( 30 )
would work just fine
Post Reply