The SQL Alias is a feature of the SQL that is supported by all the relational database management systems. The SQL alias is used to rename a table or the column of table temporarily.
The SQL alias is used when there are complex problems and the user wants to reduce the amount of the code for the query. This makes the SQL query easy to understand. The SQL alia is also used to give a shorter name to a table or a column that are having a complex name. The syntax of SQL alias for a table is as follows:
SYNTAX of SQL Alias for Table
Suppose you have the following table Employee and you want to rename it as emp:
To rename the table you will use the following query:
Select *from Employee as emp;
The following is the syntax of SQL alias for renaming a column:
Column-name as alias-name
Suppose you have the following table employee:
Suppose you want to rename the column Emp_Name of the above table then you will use the following query:
Select Emp_Name as EN from Employee;
This query will name the column Emp_Name of the table Employee as EN.
Suppose you have the following two tables Instructor and Student:
Suppose you want to extract the data from both of the above table then you will use the following SQL query:
Select I. Dept_No, I. Name, S. Name from Instructor as I, Student as S where I. Dept_No = S. Dept_No;
The above query will generate the following result:
In the above example it can be seen that those instructor names and the student names are displayed whose Dept_No match. And also we renamed the Instructor table as I and Student table as S temporarily using alias.