All Type Coding

Search Here

Alias in Sql server

Alias
Aliases are used to temporarily rename a table or a column heading.You can rename a table or a column temporarily by giving another name known as alias.The use of table aliases means to rename a table in a particular SQL statement. The renaming is a temporary change and the actual table name does not change in the database. or An alias is an alternate name that can be used to make a connection. The alias encapsulates the required elements of a connection string, and exposes them with a name chosen by the user. Aliases can be used with any client application.

Syntax:
The basic syntax of table alias is as given below:

 Select * from table_name as alias_name Where  [Condition];
 OR
 Select Column1,Column2,…. from table_name as                                        alias_name  Where [Condition];

For Example alias name for table :
Select * from Employee1 as Emp
The basic syntax of column alias is as given below:
Select Column1 as Alias_Name,Column1 as Alias_name from table_name
For Example alias name for Column:
Select
Column1 as Name
Column1 as Address
from Employee1 

Let,s Consider Employee1 table contain the data is as following.





















By the following query we give the alias name of column like Name to NameofEmployee and Salary to SalaryofEmployee 





















OR
We can the asign the alias name to the table like below. 





















We asign the alias name to table Employee to Emp.Now when we'll select the column with table alias name like above.

No comments :

Post a Comment