Tuesday 28 December 2021

How do you Rename a table in SQL?

Create Table

How do you Rename a table in SQL?

In some situations, database administrators and users want to change the name of the table in the SQL database because they want to give a more relevant name to the table.

Any database user can easily change the name by using the RENAME TABLE and ALTER TABLE statement in Structured Query Language.

Here, we have taken the following two different SQL examples, which will help you how to change the name of the SQL table in the database using RENAME statement:

Rename table syntax:

ALTER TABLE old_table_name RENAME TO new_table_name;

Rename table output:

  • First, specify the name of the table to be renaming.

  • Second, specify the name of the database in which the table was created and the name of the schema to which the table belongs. The database name is optional.

  • Third, use IF EXISTS clause to remove the table only if it exists. The IF EXISTS clause has been supported since SQL Server 2016 13.x. If you remove a table that does not exist, you will get an error. The IF EXISTS clause conditionally removes the table if it already exists.

SQL Tutorial

No comments:

Post a Comment

How do you select data from a table in SQL?

Create Table How do you select data a table in SQL? The SELECT statement is used to se...