Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Sql rename
1. 8/10/13 SQL Rename
beginner-sql-tutorial.com/sql-rename.htm 1/2
SQL RENAME Statement
With RENAME statement you can rename a table.
Some of the relational database management system (RDBMS) does not support this command, because this is
not standardizing statement.
For example renaming a table through MS SQL Server you must use storage procedure SP_RENAME.
Syntax for SQL RENAME is:
RENAME TABLE {tbl_name} TO {new_tbl_name};
Where {tbl_name} table that exists in the current database, and {new_tbl_name} is new table
name.
As for Oracle may also be use the following option:
ALTER TABLE {tbl_name} RENAME TO {new_tbl_name};
As Example
CREATE TABLE employees
( id NUMBER(6),
name VARCHAR(20)
);
INSERT INTO employees( id, name ) values( 1, 'name 1');
INSERT INTO employees( id, name ) values( 2, 'name 2');
INSERT INTO employees( id, name ) values( 3, 'name 3');
SELECT * FROM employees;
SELECT Output:
2. 8/10/13 SQL Rename
beginner-sql-tutorial.com/sql-rename.htm 2/2
id name
-------------
------
-------------
------
1 name 1
2 name 2
3 name 3
RENAME TABLE employees TO employees_new;
SELECT * FROM employees_new;
SELECT Output:
id name
-------------
------
-------------
------
1 name 1
2 name 2
3 name 3
SQL RENAME NOTES
1)The minimum version that supports table renaming is Oracle 8i. All the dependencies of the table will
automatically updated. No need of updating them after wards