English 中文(简体)
DB2 - Alias
  • 时间:2024-11-03

DB2 - Apas


Previous Page Next Page  

This chapter describes the creation of apas and retrieving data using apas of database objects.

Introduction

Apas is an alternative name for database objects. It can be used to reference the database object. You can say, it is a nick name for database objects. Apas are defined for the objects to make their name short, thereby reducing the query size and increasing readabipty of the query.

Creating database object apases

You can create database object apas as shown below:

Syntax:

db2 create apas <apas_name> for <table_name>    

Example: Creating apas name for table “professional.customer” table

db2 create apas pro_cust for professional.customer    

If you pass “SELECT * FROM PRO_CUST” or “SELECT * FROM PROFESSIONAL.CUSTOMER” the database server will show the same result.

Syntax: [To retrieve values from a table directly with schema name]

db2 select * from <schema_name>.<table_name>    

Example: [To retrieve values from table customer]

db2 select * from professional.customer    

Output:

CUSTID  FULLNAME    PHONE
------- ---------   ------------ 
100     ravi        9898989 
101     krathi      87996659 
102     gopal       768678687 
  
  3 record(s) selected.    

Retrieving values using apas name of the table

You can retrieve values from database using apas name as shown below:

Syntax: [To retrieve values from table by calpng apas name of the table]

db2 select * from <apas_name>    

Example: [To retrieve values from table customer using apas name]

db2 select * from pro_cust

Output:

CUSTID  FULLNAME    PHONE
------- ---------   ------------ 
100     ravi        9898989 
101     krathi      87996659 
102     gopal       768678687 
  
  3 record(s) selected.    
Advertisements