"Thomas Jerkins" <to*****@hotmail.com> wrote in message
news:ck*************@news.t-online.com...
When I write a create table SQL statement I want to add some information
about the column heading of each column. How does the exact syntax for the create table look like (which includes
this column data look)?
How do I add later column headings ?
I am assuming that you are using the phrase 'column heading' to mean the
title that appears above a column when you run an SQL Select from the DB2
command line or in the DB2 Command Center. For example, given:
select lastname, salary
from employee
where empno in ('000010', '000020');
results in:
LASTNAME SALARY
------------ ---------
HAAS 52750.00
THOMPSON 41250.00
I assume that your question refers to 'LASTNAME' and 'SALARY' in this result
and that you want to control what these headings are. If that's NOT what you
mean by 'column headings', please clarify.
It is possible that SQLServer, Oracle and DB2 handle these column headings
the same way as a result of complying with the same standards. Then again,
they may not not; I am only answering with respect to DB2.
The Create Table statement does not have any effect on the column heading
that appears when you query the table. To control the column heading, you
use an 'as' expression within the Select statement. For example:
select lastname as Employee_Last_Name, salary as Employee_Pay
from employee
where empno in ('000010', '000020');
results in:
EMPLOYEE_LAST_NAME EMPLOYEE_PAY
--------------------------- ------------------
HAAS 52750.00
THOMPSON 41250.00
If you want embedded blanks within the column heading, you need to embed the
column heading within quotes. For example:
select lastname as "Employee Last Name", salary as "Employee Pay"
from employee
where empno in ('000010', '000020');
results in
EMPLOYEE LAST NAME EMPLOYEE PAY
-------------------------- -----------------
HAAS 52750.00
THOMPSON 41250.00
[Please note that I "took some liberties" with the result sets shown in
these examples due to the proportional fonts used in my newsreader. In the
real world:
- the lastname values will be left-justified under the LASTNAME heading
- the salary values will be right-justified under the SALARY heading.
- the headings will always be uppercase if the query is executed in the DB2
command line but will match the case of the query if the query is executed
in the Command Center]
Rhino