RENAME command in SQL


The RENAME command in SQL is used to rename a table. Some relational database management systems (RDBMS) do not support the RENAME command, because it is not a standard command.


To learn more about the RENAME command in SQL, read the example in the following article of Taimienphi.vn.

For example, to rename a table via MS SQL Server, you must use the stored procedure SP_RENAME.

Syntax of RENAME command in SQL

RENAME TABLE {tbl_name} TO {new_tbl_name};

Of which: tables {tbl_name} exists in the current database and {new_tbl_name} is the new board name.

For Oracle, you can also use the following option:

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, ‘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:

lenh rename in sql 2

RENAME TABLE employees TO employees_new;

SELECT * FROM employees_new;

Select output:

lenh rename in sql 3

Some notes with the RENAME command in SQL

The version supports renaming tables from Oracle 8i and above. All table dependencies automatically update, you don’t need to update anything.

https://thuthuat.taimienphi.vn/lenh-rename-rong-sql-33106n.aspx
In a nutshell the RENAME command in SQL is used to rename the table. In addition, readers can refer to some other articles on Taimienphi.vn such as MS SQL Server and Oracle? Compare Oracle and SQL Server To gain a better understanding of the two most popular database management systems today.

.

Add a Comment

Your email address will not be published. Required fields are marked *