There will be times when you must rename a table. Before you do, please be aware that any objects that are dependent on the table will need to be updated as well. Access does not rename references for you as other technologies do.
This feature works the same in all modern versions of Microsoft Access: 2010, 2013, and 2016.
- Right-click on the table that you wish to rename.
- Choose Rename.
- Type the new name and hit the Enter key to confirm the name.
- Note that you will have a chance to CTRL+Z to undo right away.
RENAME TABLE allows you to rename an existing table in any schema (except the schema SYS).
To rename a table, you must either be the database owner or the table owner.
Syntax
RENAME TABLE table-Name TO new-Table-NameIf there is a view or foreign key that references the table, attempts to rename it will generate an error. In addition, if there are any check constraints or triggers on the table, attempts to rename it will also generate an error.
Statement dependency system
The RENAME TABLE statement is not allowed if there are any open cursors that reference the table that is being altered.
View Discussion
Improve Article
Save Article
View Discussion
Improve Article
Save Article
Sometimes we may want to rename our table to give it a more relevant name. For this purpose we can use ALTER TABLE to rename the name of table.
*Syntax may vary in different databases.
Syntax(Oracle,MySQL,MariaDB):
Columns can be also be given new name with the use of ALTER TABLE.
Syntax(MySQL, Oracle):
ALTER TABLE table_name RENAME COLUMN old_name TO new_name;Syntax(MariaDB):
ALTER TABLE table_name CHANGE COLUMN old_name TO new_name;Sample Table:
Student
1 | Ram | 20 |
2 | Abhi | 21 |
3 | Rahul | 22 |
4 | Tanu | 19 |
QUERY:
- Change the name of column NAME to FIRST_NAME in table Student.
OUTPUT:
1 | Ram | 20 |
2 | Abhi | 21 |
3 | Rahul | 22 |
4 | Tanu | 19 |
- Change the name of the table Student to Student_Details
OUTPUT:
Student_Details
1 | Ram | 20 |
2 | Abhi | 21 |
3 | Rahul | 22 |
4 | Tanu | 19 |
This article is contributed by Shubham Chaudhary. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or
you want to share more information about the topic discussed above.
next → ← prev
In some situations, database administrators and users want to change the name of the table in the SQL database because they want to give a more relevant name to the table.
Any database user can easily change the name by using the RENAME TABLE and ALTER TABLE statement in Structured Query Language.
The RENAME TABLE and ALTER TABLE syntax help in changing the name of the table.
Syntax of RENAME statement in SQL
Examples of RENAME statement in SQL
Here, we have taken the following two different SQL examples, which will help you how to change the name of the SQL table in the database using RENAME statement:
Example 1: Let's take an example of a table named Cars:
Hyundai Creta | White | 10,85,000 |
Hyundai Venue | White | 9,50,000 |
Hyundai i20 | Red | 9,00,000 |
Kia Sonet | White | 10,00,000 |
Kia Seltos | Black | 8,00,000 |
Swift Dezire | Red | 7,95,000 |
Table: Cars
- Suppose, you want to change the above table name into "Car_2021_Details". For this, you have to type the following RENAME statement in SQL:
- After this statement, the table "Cars" will be changed into table name "Car_2021_Details".
Example 2: Let's take an example of a table named Employee:
201 | Abhay | 25000 | Goa |
202 | Ankit | 45000 | Delhi |
203 | Bheem | 30000 | Goa |
204 | Ram | 29000 | Goa |
205 | Sumit | 40000 | Delhi |
Table: Employee
- Suppose, you want to change the name of the above table into the "Coding_Employees". For this, you have to type the following RENAME statement in SQL:
- After this statement, the table "Employee" will be changed into the table name "Coding_Employees".
Syntax of ALTER TABLE statement in SQL
In the Syntax, we have to specify the RENAME TO keyword after the old name of the table.
Examples of ALTER TABLE statement in SQL
Here, we have taken the following three different SQL examples, which will help you how to change the name of the table in the SQL database using ALTER TABLE statement:
Example 1: Let's take an example of a table named Bikes:
KTM DUKE | Black | 185,000 |
Royal Enfield | Black | NULL |
Pulsar | Red | 90,0000 |
Apache | White | NULL |
Livo | Black | 80,000 |
KTM RC | Red | 195,000 |
Table : Bikes
- Suppose, you want to change the name of the above table into "Bikes_Details" using ALTER TABLE statement. For this, you have to type the following query in SQL:
After this statement, the table "Bikes" will be changed into the table name "Bikes_Details".
Example 2: Let's take an example of a table named Student:
1001 | Abhay | 85 |
1002 | Ankit | 75 |
1003 | Bheem | 60 |
1004 | Ram | 79 |
1005 | Sumit | 80 |
Table : Student
- Suppose, you want to change the name of the above table into "MCA_Student_Details" using ALTER TABLE statement. For this, you have to type the following query in SQL:
After this statement, the table "Student" will be changed into table name "MCA_Student_Details".
Example 3: Let's take an example of a table named Employee:
201 | Abhay | 25000 | Goa |
202 | Ankit | 45000 | Delhi |
203 | Bheem | 30000 | Goa |
204 | Ram | 29000 | Goa |
205 | Sumit | 40000 | Delhi |
Table: Employee
- Suppose, you want to change the name of the above table into the "Coding_Employees" using an ALTER TABLE statement. For this, you have to type the following query in SQL:
After this statement, the table "Employee" will be changed into the table name "Coding_Employees".
Next TopicSQL TRUNCATE TABLE
← prev next →