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? Quote 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; Quote 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? Quote 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. Quote 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 Quote 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. Quote 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? Quote 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. Quote 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? Quote 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. Quote 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? Quote 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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/141285-solved-change-table-name/#findComment-739747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.