What is an ALIAS command in SQL Server, where apply alias in the database command?
What is an ALIAS command in SQL Server, where apply alias in the database command?
Software Developer
Hi, my self Ravi Vishwakarma. I have completed my studies at SPICBB Varanasi. now I completed MCA with 76% form Veer Bahadur Singh Purvanchal University Jaunpur. SWE @ MindStick | Software Engineer | Web Developer | .Net Developer | Web Developer | Backend Engineer | .NET Core Developer
SQL Aliases :
SQL aliases are used to give a temporary name to tables or columns in table. It is exist only duration of that query in perform. Alias are used to provide a easier name to table or column of table. An alias is create with use of ‘AS’ keyword.
Syntax :
Alias for column-
We can also create alias for multiple column in a table.
Alias for Table-
Example :
Lets have a table ‘Customer’,
Follow the statement is used alias for table column ‘cust_name’ as ‘name’ and ‘city’ as ‘c’ .
The following SQL statement is using alias for a table ‘Customer’ as ‘cust’.
We can also provide aliases to retrieve record from more than one table at a time like below.
We can also provide single alias for two or more columns in a table at a time. In the following statement a alias ‘name’ for column name ‘cust_name’ and ‘city’ in ‘Customer’ table.
To give space between alias name use [alias name] in SQL statement.
In the following statement select a record where customer_id=3007(Brad Davis). By using ‘Customer’ and ‘Salesman’ table and give the alias name as ‘cust’ and ‘sale’ respectively.