Zoey Posted November 5, 2006 Share Posted November 5, 2006 I created the table character, which has the following info:[code]`id` int(11) NOT NULL auto_increment, `character` varchar(255), PRIMARY KEY (`id`)[/code]However, I later realized that I wanted the column character to be called description so it matched up with some of my other tables. So using this code:[code]$sql = "ALTER TABLE `character` CHANGE `character` `description` varchar(255)";mysql_query($sql) or DIE (mysql_error());[/code]I attempted to do that. I received no error messages so I assumed everything was fine... however, when I plugged in this code:[code]$result = mysql_query("DESCRIBE `character`"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("%s %s", $row[0], $row[1]); echo"<br>"; } mysql_free_result($result) OR DIE (mysql_error());[/code]It was still displaying the following info, even after I refreshed a few times:[quote]id int(11)character varchar(255)[/quote]Instead of:[quote]id int(11)description varchar(255)[/quote]I dont have access to my server directly, so I have to make these adjustments via PHP. I'm really hoping that someone can help me. Thanks SO much! Link to comment https://forums.phpfreaks.com/topic/26207-changing-the-column-name-of-a-mysql-table/ Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 Only thing I can think of is to add the NOT NULL at the end of you query.$sql = "ALTER TABLE `character` CHANGE `character` `description` varchar(255) NOT NULL";not sure if that helps any but I triedCheers!Stephen Link to comment https://forums.phpfreaks.com/topic/26207-changing-the-column-name-of-a-mysql-table/#findComment-119894 Share on other sites More sharing options...
almightyegg Posted November 5, 2006 Share Posted November 5, 2006 should be:[code]$sql = "ALTER TABLE `character` RENAME `description`";[/code]that should work :)(WOO my 100th post) Link to comment https://forums.phpfreaks.com/topic/26207-changing-the-column-name-of-a-mysql-table/#findComment-120016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.