To delve deeper into the SQL RENAME command, readers can refer to examples in the following article by Mytour.
For instance, to rename a table via MS SQL Server, you must utilize the stored procedure SP_RENAME.
Syntax of the SQL RENAME Command
RENAME TABLE {tbl_name} TO {new_tbl_name};
Where: the table {tbl_name} exists in the current database and {new_tbl_name} represents the new table name.
For Oracle, the following option can also be used:
Use ALTER TABLE {tbl_name} RENAME TO {new_tbl_name};
For example:
CREATE TABLE employees
( id NUMBER(6),
name VARCHAR(20)
);
INSERT INTO employees( id, name ) VALUES( 1, 'John Doe');
INSERT INTO employees( id, name ) VALUES( 2, 'Jane Smith');
INSERT INTO employees( id, name ) VALUES( 3, 'John Smith');
SELECT * FROM employees;
Output selection:
RENAME TABLE employees TO new_employees;
SELECT * FROM new_employees;
Output selection:
Some notes on the SQL RENAME command
The renaming command is supported from Oracle 8i onwards. All table dependencies will automatically update, eliminating the need for manual updates.
In summary, the SQL RENAME command is used to change the name of a table. Additionally, readers can explore other articles on Mytour such as 'What are MS SQL Server and Oracle? Compare Oracle and SQL Server' to gain a better understanding of the two most popular database management systems today.
