Site icon IT Tutorial

Rename Table in Oracle

I will explain Rename Table in Oracle in this post.

 

Rename Table in Oracle

 

Alter Table

You can perform the following tasks using the Alter command in Oracle

 

 

 

Rename Table 

 

 

Syntax

rename::=

 

alter table table_name rename to new_table_name;

RENAME TABLE table-Name TO new-Table-Name;

 

You can rename an existing table as follows.

alter table hr.employees rename to myemployee;











You can add new column as follows.

ALTER TABLE People ADD DateOfBirth date;



You can drop an existing column as follows.

ALTER TABLE People DROP COLUMN DateOfBirth;

You can rename column name as follows using alter command.

 alter table hr.employees rename column employee_id to emp_id;

 

You can convert table into read-only and read write mode as follows.

alter table hr.employees read only;


SQL> alter table msdeveci.mytest read only;

Table altered.

SQL> alter table msdeveci.mytest read write;

Table altered.

SQL>

 

You can add new partition to existing table as follows.

alter table hr.employees add partition part values (‘G3_201407_07');

 

You can add primary key or constraint as follows.

ALTER TABLE HR.EMPLOYEES ADD (CONSTRAINT EMP_EMP_ID_PK PRIMARY KEY (EMP_ID));

 

You can disable and enable existing contraint as follows.

 ALTER TABLE HR.DEPARTMENTS DISABLE CONSTRAINT DEPT_LOC_FK;


ALTER TABLE HR.DEPARTMENTS ENABLE CONSTRAINT DEPT_LOC_FK;

 

You can rename an existing table as follows.

SQL> alter table msdeveci.test_table rename to mytest;   

Table altered.

SQL>

 

You can add new column, drop existing column and modify column as follows.

SQL> alter table msdeveci.mytest add city varchar2(24);

Table altered.

SQL> alter table msdeveci.mytest modify city varchar2(36);

Table altered.



SQL> alter table msdeveci.mytest drop column city;

Table altered.

SQL>

 

 

 

 

 

Dou want to learn Oracle SQL Tutorial for Beginners, then read the following articles.

Oracle SQL Tutorials For Beginners – Learn Oracle SQL from scratch with Oracle SQL Online Course

Exit mobile version