Renaming a Table : Rename Table « Table Index « SQL / MySQL






Renaming a Table

/*

mysql> CREATE TABLE student (
    ->     id INT NOT NULL AUTO_INCREMENT,
    ->     name VARCHAR (50),
    ->     email VARCHAR (50),
    ->     PRIMARY KEY (id)
    -> );
Query OK, 0 rows affected (0.05 sec)

mysql> Show tables;
+-------------+
| Tables_in_t |
+-------------+
| bird        |
| cloth       |
| employee    |
| event       |
| man         |
| person      |
| report      |
| sales       |
| shirt       |
| student     |
| timetable   |
+-------------+
11 rows in set (0.01 sec)

mysql> /* Renaming a Table */
mysql> ALTER TABLE student RENAME MyUsers;
Query OK, 0 rows affected (0.01 sec)

mysql> Show tables;
+-------------+
| Tables_in_t |
+-------------+
| bird        |
| cloth       |
| employee    |
| event       |
| man         |
| myusers     |
| person      |
| report      |
| sales       |
| shirt       |
| timetable   |
+-------------+
11 rows in set (0.01 sec)


*/
Drop TABLE student;

CREATE TABLE student (
    id INT NOT NULL AUTO_INCREMENT,
    name VARCHAR (50),
    email VARCHAR (50),
    PRIMARY KEY (id)
);

Show tables;
  
/* Renaming a Table */
ALTER TABLE student RENAME MyUsers;

Show tables;

           
       








Related examples in the same category