Changing the table name to a relevant name can be needed often in the databases. Not only the table but the column names can be also changed as per the added information. For the same, we can use ALTER (RENAME) in SQL to rename the names of tables or columns. The ways of altering or changing the table can differ in each database.
- Syntax of ALTER TABLE (To RENAME table) –
ALTER TABLE table_name RENAME TO new_table_name;
- Syntax of ALTER TABLE (To RENAME column name) –
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;
Demo Table –
Product Table
Category | Region | City | Country | Customer_ID | Customer_name |
Technology | West | Aurora | United States | TP-21565 | Tracy Poddar |
Office Supplies | West | Aurora | United States | TP-21565 | Tracy Poddar |
Office Supplies | West | Pasadena | United States | HA-14920 | Helen Andreada |
Furniture | West | Pasadena | United States | HA-14920 | Helen Andreada |
Office Supplies | West | Mesa | United States | HJ-14875 | Heather Jas |
Example – Consider the Product table of the Customer database where we have to change the column name from “Customer Name” To “Name” using ALTER (RENAME).
ALTER TABLE [dbo].[Products] RENAME COLUMN [Customer Name] TO [Name];
Other SQL topics to check out:
- How to write SQL Select Statements
- Introduction to SQL for Data Scientists
- What is RDBMS (Relational Database Management System)?
- SQL WHERE Clause
- SQL LIKE Operator
- SQL OR Operator
- SQL ALL Operator
Follow us on Twitter, Facebook, Linkedin, and Tableau Public to stay updated with our latest blog and what’s new in Tableau.
If you are looking forward to getting your data pipeline built and setting up the dashboard for business intelligence, book a call now from here.
#analytics #data #business #artificialintelligence #machinelearning #startup #deeplearning #deeplearning #datascience #ai #growth #dataanalytics #india #datascientist #powerbi #dataanalysis #tableau #SQL #businessanalytics #businessanalyst #businessandmanagement #dataanalyst #businessanalysis #analyst #analysis #powerbideveloper #powerbidesktop #letsviz