daveoffy Posted January 18, 2009 Share Posted January 18, 2009 I have a table named members, using SQL how can I change the name to profiles? Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/ Share on other sites More sharing options...
corbin Posted January 18, 2009 Share Posted January 18, 2009 RENAME TABLE name1 TO name2; Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739498 Share on other sites More sharing options...
daveoffy Posted January 18, 2009 Author Share Posted January 18, 2009 for a column will i do RENAME COLUMN c1 To c2? Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739499 Share on other sites More sharing options...
Daniel0 Posted January 18, 2009 Share Posted January 18, 2009 for a column will i do RENAME COLUMN c1 To c2? No, take a look at ALTER TABLE. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739660 Share on other sites More sharing options...
daveoffy Posted January 18, 2009 Author Share Posted January 18, 2009 So I would use... ALTER COLUMN c1 TO c2 Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739731 Share on other sites More sharing options...
fenway Posted January 18, 2009 Share Posted January 18, 2009 There are some ways to rename without using alter, but don't use them... bad form. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739732 Share on other sites More sharing options...
daveoffy Posted January 18, 2009 Author Share Posted January 18, 2009 So am I right? Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739734 Share on other sites More sharing options...
fenway Posted January 18, 2009 Share Posted January 18, 2009 No, you need to do: ALTER TABLE yourTable CHANGE oldColName newColName <column def> But you NEED to make sure you use the exact same column defn as current exists. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739738 Share on other sites More sharing options...
daveoffy Posted January 18, 2009 Author Share Posted January 18, 2009 what is column def? Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739740 Share on other sites More sharing options...
Daniel0 Posted January 18, 2009 Share Posted January 18, 2009 Stuff like its type, default value, etc. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739742 Share on other sites More sharing options...
daveoffy Posted January 18, 2009 Author Share Posted January 18, 2009 why do I need to put column def? Is there a way to do it without that? Or can you give me an example on how column def looks like? Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739744 Share on other sites More sharing options...
Daniel0 Posted January 18, 2009 Share Posted January 18, 2009 Yes, you do need to do that (hence the capitalized "NEED" in fenway's post). You are telling MySQL this: "In the table something, change the column x to be this: ...". The last part of it is the same syntax as when you are creating a table. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739745 Share on other sites More sharing options...
fenway Posted January 18, 2009 Share Posted January 18, 2009 "Show create table" will tell you what it is. Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.