DB2 - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

DB2 Alias

DB2 Alias

shape Description

DB2 Alias are used to give a temporary and customize and more readable name of a database column while retrieving value with a select query. We can also give a alias to a table. It will help us to shorten the table name while performing join on a tables. The database DB2 is utilized to deal with a wide assortment of information, for example, the outcome of exploration tests, document assets for organization managers, or the areas and serial quantities of bits of hardware's. At first, IBM had created the product of DB2 for the platforms that are explicit and in the year 1990, Universal Database DB2 Server has been developed, which can keep running on any legitimate working frameworks, for example, Windows,UNIX, and Linux.

shape Syntax

The DB2 Alias syntax for a column is as follows:
db2 create alias for <table_name> Table_name => The accurate table name in the database Alias_name => The operations that can be performed on a column in the table.

shape Examples

If we want to join 'student_details' table with 'dept' table then we can use aliases to avoid use of long table name. [c] SELECT d.dept_num, std. student_name, std. student_id FROM dept d INNER JOIN student_details std ON d.dept_num = std.dept_num;[/c]

Using Aliases for columns

shape Description

Aliases are defined for columns and tables. Basically aliases are created to make the column selected more readable.

shape Examples

To select the first name of all the employees, the query would be like: TABLE NAME: EMPLOYEE_NAME
First Name Last Name
Michel Kors
Jhon Ceana
[c]SELECT FIRST_NAME FULL_NAME FROM EMPLOYEE_NAME;[/c] Output -
Full Name
Michel
Jhon

Summary

shape Key Points

  • DB2 Alias - Used to give a temporary and customise and more readable name of a database column.