EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle rename table

Oracle rename table

Updated March 6, 2023

Oracle rename table

Introduction to Oracle rename table

Oracle provides the rename table facility to the user, in which we can rename the existing table name as per our requirement. When we rename the table name at that time oracle automatically transfers all rights such as indexes, constraints, and grants on the old table name to the new table name. at the same additionally, oracle invalidates all objects that depend on that specified rename table name such as views, functions, procedure, and synonyms. For renaming table names we can use two different types of command such as rename table name command and alter table name command.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax

rename  old specified table name to new specified table name;

Explanation

In the above syntax, we use rename table command to change the existing table name, view, sequence, or synonym, here the old specified table name means existing table name, to is the keyword for reference purpose and the new specified table name is used for a new name for exiting table name. The newly renamed name must not already be used for another.

How to rename a table in Oracle?

Now let’s see how we can rename the table in oracle as follows.

Basically, there are two ways to rename the table first by using rename command and the second is that by using alter table name command. Both commands are very simple. We can easily rename the table name but we must have some privilege to rename the table name. We either have a database owner or table owner then and then we are able to rename the table name. Another main point is that we need an existing table to perform the rename command. Rename the command syntax we already discussed in the above point. Table names must be unique and if there is any dependence on that table and we need to perform the rename command at that time we can rename the table name but cannot rename synonyms that depend on that table.

Examples

Now let’s see the different examples of oracle rename tables for better understanding as follows.

First, we need an existing table to perform the rename table command, so let’s create a table by using the following statement as follows.

create table product(
product_id int,
product_name varchar(255) not null,
product_cost decimal(15,2) not null,
primary key (product_id));

Explanation

In the above example, we used a create table to create a new table name as a product, here the product is the new table and we created it with different attributes as shown in the above statement. When we execute the above query then the final output we illustrate by using the following snapshot.

Oracle rename table output 1

Now we are able to perform the rename statement as follows.

rename product to new_product;

Explanation

In the above example, we use a rename statement to rename the existing table name, here the product is the old table name that we need to rename, and to is the keyword for referencing the new name, new_product is the new renamed name of the existing table. When we execute the above query then the final output we illustrate by using the following snapshot.

Oracle rename table output 2

Now let’s see another way to rename the table name as follows.

Syntax

alter table specified table name rename to new table name;

Explanation

In above syntax we use alter table command to rename the table name, here specified table name means existing table name, rename to is the keywords used to rename the table name after that we mentioned the new table name as shown in above syntax.

Example 

In this example, we used an already created table name as a new_product.

alter table new_product rename to product_demo;

Explanation

In the above example, we use the alter table command to rename the table name, here the new_product is the existing table name that we need to rename and product_demo is the new name of the existing table that we renamed. When we execute the above query then the final output we illustrate by using the following snapshot.

Oracle rename table output 3

  • Now insert some records into the table by using the insert into the statement and then perform the rename table command as follows.

After inserting records in the product_demo table, use a select statement to see the records.

select * from product_demo;

When we execute the above query then the final output we illustrate by using the following snapshot.

output 4

Now perform the rename command to check if it transfers all constraints to the renamed table or not as follows.

rename product_demo to product_sample;

After executing the above query, now see the content of the new rename table as follows.

select * from product_sample;

When we execute the above query then the final output we illustrate by using the following snapshot.

output 5

Explanation

Now see the difference before the rename table and after the rename table. The below screenshot shows the inserted records of product_demo as below.

Rules and regulation for rename table

Now let’s see the different rules and regulations for rename table statements as follows.

  1. The new name of the specified table must be unique that means the name of the table does not already exist otherwise it will get an error like the name is already used.
  2. When we need to rename the table name we must have the privilege to rename the table that means we must either be the database owner or the table owner.
  3. All data definition language-related queries we can execute in auto-commit mode, which means once we rename the table name then we are not able to revert it back.
  4. If the table consists of a view or foreign key that references the specified table and we need to rename that table at that time it shows the error message. On the other hand, if there is any constraint or triggers on that table and we attempt to rename that table then it will also show the error message.
  5. If there is any open cursor and that references the specified table in this situation the rename statement is not working.

Conclusion

We hope from this article you have understood about the Oracle rename table. From this article, we have learned the basic syntax of rename tables and we also see different examples of rename tables. From this article, we learned how and when we use the Oracle rename table.

Recommended Articles

This is a guide to Oracle rename table. Here we discuss the basic syntax of rename tables and we also see different examples of rename tables. You may also have a look at the following articles to learn more –

  1. Oracle Tablespace
  2. Oracle Bitmap Index
  3. Oracle Synonyms
  4. PIVOT in Oracle
GOLANG Course Bundle - 6 Courses in 1
23+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
iOS DEVELOPER Course Bundle - 61 Courses in 1
147+ Hours of HD Videos
61 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
JAVA SERVLET Course Bundle - 18 Courses in 1 | 6 Mock Tests
56+ Hours of HD Videos
18 Courses
6 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
RED HAT LINUX Course Bundle - 5 Courses in 1
28+ Hours of HD Videos
5 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
ORACLE DBA Database Management System Course Bundle - 2 Courses in 1
 20+ Hours of HD Videos
2 Courses
Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more