Tuesday, October 31, 2017

SQL RENAME Statement

SQL RENAME Statement


SQL RENAME TABLE syntax is used to change the name of a table. Sometimes, we choose non-meaningful name for the table. So it is required to be changed.

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};For Example;create table states(id NUMBER (6),name VARCHAR (20));INSERT INTO STATES (id, name) values(1,'delhi');INSERT INTO STATES (id, name) values(2,'Punjab');INSERT INTO STATES (id, name) values(3,'Gurgaon');INSERT INTO STATES (id ,name) values (4,'Noida');SQL> select * from states;SELECT Output:        ID NAME---------- --------------------         1 delhi         2 Punjab         3 Gurgaon         4 NoidaNow Rename start---SQL> alter table states rename to cities;
Table altered.
SQL> select * from cities;SELECT Output:        ID NAME---------- --------------------         1 delhi         2 Punjab         3 Gurgaon         4 Noida

No comments:

Post a Comment

How to create user in MY SQL

Create  a new MySQL user Account mysql > CREATE USER ' newuser '@'localhost' IDENTIFIED BY ' password '...