- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference Rename and Alias In DBMS
In this article, we are going to study Rename and Alias. Both these have their specific role when we talk in terms of DBMS. Renaming and aliases to the elements of the database provide a layer of abstraction and make the attributes of the relation presentable for the viewer. Mostly, Database store crucial information the concepts of renaming and aliasing plays an important role in representing data with efficiency. Let's gain an understanding of these concepts, their syntax, and the difference between them.
What is Alias?
Alias is an alternative name given to a column in the database Management System. This practice offers the advantage of assigning distinct and easily recognizable names to columns, enhancing their specificity.
Let’s Look Into its Syntax
Select columnName As AliasName from TableName;
For instance
Consider a table "Employee" containing attributes such as name, eid, salary, designation, and D.O.J. In a scenario where only the salary column is to be displayed with the name of "Annual-Salary," the concept of alias comes into play. This is achieved by employing the "AS" keyword, which serves as a reference to the assigned alias.
Original Table
empid | emp_name | salary |
---|---|---|
101 | Sam | 20000 |
102 | Carl | 30000 |
103 | Tom | 40000 |
104 | Nick | 70000 |
Select empid, Salary AS Annual_Salary from Employee;
Output
empid | Annual_Salary |
---|---|
101 | 20000 |
102 | 30000 |
103 | 40000 |
104 | 70000 |
You can apply the Alias name concept on multiple columns in one query.
Alias Name for Table
It helps to differentiate the column from the different tables that may or may not have the same name.
Let’s understand the concept of Alias name for a table by the below example
Manager Table
Managerid | empid | ManagerName |
---|---|---|
1001 | 101 | Sam |
1002 | 104 | Nick |
Employee table
empid | emp_name | salary |
---|---|---|
101 | Sam | 20000 |
102 | Carl | 30000 |
103 | Tom | 40000 |
104 | Nick | 70000 |
Select E.empid , M.empid , Salary from Employee As E , Manager As M
Where E.empid = M.empid ;
Output
empid | Salary |
---|---|
101 | 20000 |
104 | 70000 |
In the example provided earlier, "E" and "M" serve as aliases for the "Employee" and "Manager" tables, respectively. The utilization of aliases becomes particularly relevant when distinguishing between the "empid" values in these tables. This is where the concept of aliasing comes into effect. The "WHERE" clause, in this context, facilitates the identification of shared rows that possess identical "empid" values across both tables.
What is Rename?
So far you explored the Alias now, you will get an idea about the Rename concept in Database and how to use it. It is used to change the name of an object table, or column. This practice holds the purpose of attributing meaningful and relevant names to these elements. These designated names, though temporary and not permanent alter the structure of the tables.
Let's Look Into its Syntax
RENAME TableName TO NewName
Consider, for instance, an "Employee" table; through renaming, we can metamorphose it into a more contextual and expressive title.
Rename Employee TO Emp;
This syntax can be different for different databases and different databases can have their own norms and set of rules which we have to follow while renaming the table and column names.
By altering column names – such as changing salary to YearlySal. You can heighten the readability and comprehensibility of data, all the while preserving the original structure of the table.
Syntax
ALTER TABLE TableName RENAME COLUMN OldColumn TO New Column;
For Instance
ALTER TABLE EMP RENAME Salary TO YearlySal;
Output
empid | Annual_Salary |
---|---|
101 | 20000 |
102 | 30000 |
103 | 40000 |
104 | 70000 |
Difference Between the Rename and Alias
"Alias" and "Rename" are concepts frequently utilized in the context of databases, each serving distinct roles. Let’s see the difference between them by using the table mentioned below −
Characteristics | Alias | Rename |
---|---|---|
Purpose |
An alias provides a provisional or substitute name for a table or column within a specific query. Its purpose is to enhance query legibility, simplify complex queries, and assign more descriptive labels to columns or expressions in the query result. These aliases are confined to the scope of an individual query and have no impact on the official names of database objects in the schema. |
Renaming involves altering the name of a database object—such as a table, column, index, or constraint—within the actual database schema. This name change is persistent across the entirety of the database. Renaming proves valuable when striving to align names with the true purpose of an object or to rectify naming errors. |
Scope |
This changes the names temporarily and does not affect the structure of the table. |
This changes the name permanently like the table name Employee to emp in the above case. |
Keyword use |
In the case of Alias, the column name is achieved by using ‘AS’ or without AS |
In this, we can change the column name by using the Alter table statement along with RENAME |
Example |
SELECT e.empid, d.empid, e.first_name AS "FirstName", d.department_name |
ALTER TABLE old_table_name |
Conclusion
An alias offers a momentary label used in a single query to enhance query clarity and temporarily assign names to columns or tables. In contrast, renaming represents a lasting modification that changes the actual name of a database object across the entire database schema.