Rename a table in MySQL

前端 未结 16 1313
逝去的感伤
逝去的感伤 2020-12-04 07:08

Renaming a table is not working in MySQL

RENAME TABLE group TO member;

The error message is



        
相关标签:
16条回答
  • 2020-12-04 07:14
    RENAME TABLE tb1 TO tb2;
    

    tb1 - current table name. tb2 - the name you want your table to be called.

    0 讨论(0)
  • 2020-12-04 07:14

    You can use

    RENAME TABLE `group` TO `member`;
    

    Use back tick (`) instead of single quote (').

    0 讨论(0)
  • 2020-12-04 07:16

    group is a keyword (part of GROUP BY) in MySQL, you need to surround it with backticks to show MySQL that you want it interpreted as a table name:

    RENAME TABLE `group` TO `member`;
    

    added(see comments)- Those are not single quotes.

    0 讨论(0)
  • 2020-12-04 07:16

    group - is a reserved word in MySQL, that's why you see such error.

    #1064 - You have an error in your SQL syntax; check the manual that corresponds
            to your MySQL server version for the right syntax to use near 'group 
            RENAME TO member' at line 1
    

    You need to wrap table name into backticks:

    RENAME TABLE `group` TO `member`;
    
    0 讨论(0)
  • 2020-12-04 07:16

    Try any of these

    RENAME TABLE `group` TO `member`;
    

    or

    ALTER TABLE `group` RENAME `member`;
    
    0 讨论(0)
  • 2020-12-04 07:19

    According to mysql docs: "to rename TEMPORARY tables, RENAME TABLE does not work. Use ALTER TABLE instead."

    So this is the most portable method:

    ALTER TABLE `old_name` RENAME `new_name`;
    
    0 讨论(0)
提交回复
热议问题