|
|||||||
|
|
![]() |
|
|
|
|
||
|
SQL Field Reference File Hey, Ted: I've noticed that a lot of Midrange Guru tips have to do with SQL. SQL is fine for a query language, but we're not using it as a data-definition language for one big reason. The reason we don't use SQL to define tables is that there is no support for a field reference file, as there is in DDS. We like the idea of having the definitions of common fields in a file, where we can reference them when creating other tables. --Dave If you are at V5R2, or can get there, you can define a table based on the attributes of other tables. For example, here's the definition for the field reference file, FIELDREF. create table mylib/fieldref ( CompanyNo dec (3,0), CustomerNo dec (5,0), AddressLine char (25), City char (16), State char (2), ZipCode char (10), PhoneNo char (13)) V5R2 allows you to select columns from one or more tables when creating a new table. Here's the SQL statement that creates a table named CUSTOMERS.
create table mylib/Customers as
(select CompanyNo, CustomerNo,
AddressLine as Address1,
AddressLine as Address2,
City, State, ZipCode,
decimal(0,7,2) as CreditLimit,
PhoneNo as Phone,
PhoneNo as Fax
from mylib/fieldref)
definition only
All but one field was defined in the field reference file. The credit limit field had no counterpart in the field reference file, so I defined it with the decimal function. The term "definition only," in the last line, tells SQL that no data is to be copied from the FIELDREF table. The alternative is to use the term "with data," which tells SQL to load the new table with data from the select. In this case, it doesn't matter which one you use, since there is no data in the field reference file. --Ted
|
Editors
Contact the Editors |
| Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |