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