EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

Oracle rename table

Home » Data Science » Data Science Tutorials » Oracle Tutorial » Oracle rename table

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.

Syntax

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • 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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

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

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

Let’s Get Started

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

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

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

EDUCBA

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

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

Special Offer - Oracle Course Training Learn More