DB2 Server for VSE & VM: SQL Reference


Appendix D. Sample Tables

The sample tables illustrated in this appendix are used in examples throughout the DB2 Server for VSE & VM library. These tables simulate a database created for use in organization or project management applications. As a group, the tables include information that describes employees, departments, projects, and activities. This appendix contains the following sample tables:


Relationships Among the Tables

Figure 9 shows the relationships among many of the tables. These relationships are established by referential constraints, where a foreign key in the dependent table references a primary key in the parent table. In the figure, the referential constraint is symbolized by lines joining the keys; the arrowheads point from the primary key to the foreign key. Only those columns named as foreign or primary keys are listed in the figure. All tables have additional columns. You can easily review the contents of any table by executing an SQL statement, such as SELECT * FROM SQLDBA.DEPARTMENT.

Figure 9. Relationships among Tables in the Sample Application

               DEPARTMENT                      PROJECT
            *--------------*               *---------------*
     *------+---DEPTNO-----+-------*       |   PROJNO------+---------*
     |   *--+-->MGRNO      |   RESTRICT----+-->DEPTNO      |         |
     |   |  |    ...       |        *------+-->RESPEMP     |         |
     |   |  |              |        |      |    ...        |         |
     |   |  *--------------*        |      |               |         |
     |   |                          |      *---------------*    RESTRICT
    SET  |                          |                                |
   NULL  |         *----SET NULL----*                                |
     |   |         |                                                 |
     |  SET        |                                                 |
     |  NULL       |                                                 |
     |   |      EMPLOYEE                              ACTIVITY       |
     |   |  *------+-------*                       *-------------*   |
     |   *--+---EMPNO------+--*                    |   ACTNO-----+*  |
     *------+-->WORKDEPT   |  |                    |    ...      ||  |
            |    ...       |  |                    |             ||  |
            |              |  |                    *-------------*|  |
            *--------------*  |                                   |  |
                           CASCADE                                |  |
                              |                                   |  |
                              |                             RESTRICT |
           *------------------*                                   |  |
           |                                                      |  |
           |        EMP_ACT                    PROJ_ACT           |  |
           |  *-------------------*        *------------------*   |  |
           *--+->EMPNO            |       *+--PROJNO <--------+---+--'
              |  PROJNO <-----.   |RESTRICT+--ACTNO <---------+---*
              |  ACTNO <------+---+---'   '+--ACTSTDATE       |
              |  EMSTDATE <---'   |        |   ...            |
              |   ....            |        |                  |
              |                   |        *------------------*
              *-------------------*
 


ACTIVITY Table

The ACTIVITY tables describes the activities that can be performed during a project. The table acts as a master list of possible activities, identifying the activity number, and providing a description of the activity.
Name: ACTNO ACTKWD ACTDESC
Type: smallint not null char(6) not null varchar(20) not null
Desc: Activity number Activity keyword Activity description
Values: 10 MANAGE Manage/advise

20 ECOST Estimate cost

30 DEFINE Define specs

40 LEADPR Lead program/design

50 SPECS Write specs

60 LOGIC Describe logic

70 CODE Code programs

80 TEST Test programs

90 ADMQS Adm query system

100 TEACH Teach classes

110 COURSE Develop courses

120 STAFF Pers and staffing

130 OPERAT Oper computer sys

140 MAINT Maint software sys

150 ADMSYS Adm operating sys

160 ADMDB Adm databases

170 ADMDC Adm data comm

180 DOC Document

Relationship of ACTIVITY to Other Tables

ACTIVITY is a parent of the PROJ_ACT table.


CL_SCHED Table

The CL_SCHED table describes a classroom schedule.
Name: CLASS_CODE DAY STARTING ENDING
Type: char(7) not null smallint not null time not null time not null
Desc: Class code (room:teacher) Day number of 4 day schedule Class start time Class end time
Values: 101:KAR 2 14.10.00 16.10.00
  202:LMM 3 14.40.00 16.40.00
  303:RAR 4 09.00.00 09.40.00


DEPARTMENT Table

The DEPARTMENT table describes each department in the business and identifies its manager and the department to which it reports.
Name: DEPTNO DEPTNAME MGRNO ADMRDEPT
Type: char(3) not null varchar(29) not null char(6) char(3) not null
Desc: Department number Name describing general activities of department Employee number (EMPNO) of department manager Department (DEPTNO) that this department reports to
Values: A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00
  B01 PLANNING 000020 A00
  C01 INFORMATION CENTER 000030 A00
  D01 DEVELOPMENT CENTER ? A00
  D11 MANUFACTURING SYSTEMS 000060 D01
  D21 ADMINISTRATION SYSTEMS 000070 D01
  E01 SUPPORT SERVICES 000050 A00
  E11 OPERATIONS 000090 E01
  E21 SOFTWARE SUPPORT 000100 E01

Relationship of DEPARTMENT to Other Tables

DEPARTMENT is a parent of the EMPLOYEE and PROJECT tables.

The DEPARTMENT table is a dependent of the EMPLOYEE table; the MGRNO column is the foreign key in the DEPARTMENT table and references EMPNO, the primary key in the EMPLOYEE table.


EMPLOYEE Table

The EMPLOYEE table identifies all employees by an employee number and lists basic personnel information.
Names: EMPNO FIRSTNME MIDINIT LASTNAME WORKDEPT PHONENO HIREDATE
Type: char(6) not null varchar(12) not null char(1) not null varchar(15) not null char(3) char(4) date
Desc: Employee number First name Middle initial Last name Department (DEPTNO) in which the employee works Phone number Date of hire

JOB EDLEVEL SEX BIRTHDATE SALARY BONUS COMM
char(8) smallint not null char(1) date dec(9,2) dec(9,2) dec(9,2)
Job Number of years of formal education Sex (M male, F female) Date of birth Yearly salary Yearly bonus Yearly commission

The following table lists the values in the EMPLOYEE table:
  EMPNO   FIRSTNAME MID INIT   LASTNAME WORK DEPT PHONE NO   HIREDATE       JOB EDUC LEVEL       SEX   BIRTHDATE   SALARY   BONUS   COMM
char(6) not null varchar(12) not null char(1) not null varchar(15) not null char(3) char(4) date char(8) smallint not null char(1) date dec(9,2) dec(9,2) dec(9,2)
000010 CHRISTINE I HAAS A00 3978 1965-01-01 PRES 18 F 1933-08-24 52750 1000 4220
000020 MICHAEL L THOMPSON B01 3476 1973-10-10 MANAGER 18 M 1948-02-02 41250 800 3300
000030 SALLY A KWAN C01 4738 1975-04-05 MANAGER 20 F 1941-05-11 38250 800 3060
000050 JOHN B GEYER E01 6789 1949-08-17 MANAGER 16 M 1925-09-15 40175 800 3214
000060 IRVING F STERN D11 6423 1973-09-14 MANAGER 16 M 1945-07-07 32250 500 2580
000070 EVA D PULASKI D21 7831 1980-09-30 MANAGER 16 F 1953-05-26 36170 700 2893
000090 EILEEN W HENDERSON E11 5498 1970-08-15 MANAGER 16 F 1941-05-15 29750 600 2380
000100 THEODORE Q SPENSER E21 0972 1980-06-19 MANAGER 14 M 1956-12-18 26150 500 2092
000110 VINCENZO G LUCCHESSI A00 3490 1958-05-16 SALESREP 19 M 1929-11-05 46500 900 3720
000120 SEAN   O'CONNELL A00 2167 1963-12-05 CLERK 14 M 1942-10-18 29250 600 2340
000130 DOLORES M QUINTANA C01 4578 1971-07-28 ANALYST 16 F 1925-09-15 23800 500 1904
000140 HEATHER A NICHOLLS C01 1793 1976-12-15 ANALYST 18 F 1946-01-19 28420 600 2274
000150 BRUCE   ADAMSON D11 4510 1972-02-12 DESIGNER 16 M 1947-05-17 25280 500 2022
000160 ELIZABETH R PIANKA D11 3782 1977-10-11 DESIGNER 17 F 1955-04-12 22250 400 1780
000170 MASATOSHI J YOSHIMURA D11 2890 1978-09-15 DESIGNER 16 M 1951-01-05 24680 500 1974
000180 MARILYN S SCOUTTEN D11 1682 1973-07-07 DESIGNER 17 F 1949-02-21 21340 500 1707
000190 JAMES H WALKER D11 2986 1974-07-26 DESIGNER 16 M 1952-06-25 20450 400 1636
000200 DAVID   BROWN D11 4501 1966-03-03 DESIGNER 16 M 1941-05-29 27740 600 2217
000210 WILLIAM T JONES D11 0942 1979-04-11 DESIGNER 17 M 1953-02-23 18270 400 1462
000220 JENNIFER K LUTZ D11 0672 1968-08-29 DESIGNER 18 F 1948-03-19 29840 600 2387
000230 JAMES J JEFFERSON D21 2094 1966-11-21 CLERK 14 M 1935-05-30 22180 400 1774
000240 SALVATORE M MARINO D21 3780 1979-12-05 CLERK 17 M 1954-03-31 28760 600 2301
000250 DANIEL S SMITH D21 0961 1969-10-30 CLERK 15 M 1939-11-12 19180 400 1534
000260 SYBIL P JOHNSON D21 8953 1975-09-11 CLERK 16 F 1936-10-05 17250 300 1380
000270 MARIA L PEREZ D21 9001 1980-09-30 CLERK 15 F 1953-05-26 27380 500 2190
000280 ETHEL R SCHNEIDER E11 8997 1967-03-24 OPERATOR 17 F 1936-03-28 26250 500 2100
000290 JOHN R PARKER E11 4502 1980-05-30 OPERATOR 12 M 1946-07-09 15340 300 1227
000300 PHILIP X SMITH E11 2095 1972-06-19 OPERATOR 14 M 1936-10-27 17750 400 1420
000310 MAUDE F SETRIGHT E11 3332 1964-09-12 OPERATOR 12 F 1931-04-21 15900 300 1272
000320 RAMLAL V MEHTA E21 9990 1965-07-07 FIELDREP 16 M 1932-08-11 19950 400 1596
000330 WING   LEE E21 2103 1976-02-23 FIELDREP 14 M 1941-07-18 25370 500 2030
000340 JASON R GOUNOT E21 5698 1947-05-05 FIELDREP 16 M 1926-05-17 23840 500 1907

Relationship of EMPLOYEE to Other Tables

The EMPLOYEE table is a parent of the DEPARTMENT table, the PROJECT table, and the EMP_ACT table.

The EMPLOYEE table is a dependent of the DEPARTMENT table; the foreign key on the WORKDEPT column in the EMPLOYEE table references the primary key on the DEPTNO column in the DEPARTMENT table.


EMP_ACT Table

The EMP_ACT table identifies the employee performing each activity listed for each project.
Name: EMPNO PROJNO ACTNO EMPTIME EMSTDATE EMENDATE
Type: char(6) not null char(6) not null smallint not null dec(5,2) date date
Desc: Employee number Project number Activity number Proportion of employee's full time to be spent on one project Date activity starts Date activity ends
Values: 000010 AD3100 10 .50 1982-01-01 1982-07-01
  000070 AD3110 10 1.00 1982-01-01 1983-02-01
  000230 AD3111 60 1.00 1982-01-01 1982-03-15
  000230 AD3111 60 .50 1982-03-15 1982-04-15
  000230 AD3111 70 .50 1982-03-15 1982-10-15
  000230 AD3111 80 .50 1982-04-15 1982-10-15
  000230 AD3111 180 1.00 1982-10-15 1983-01-01
  000240 AD3111 70 1.00 1982-02-15 1982-09-15
  000240 AD3111 80 1.00 1982-09-15 1983-01-01
  000250 AD3112 60 1.00 1982-01-01 1982-02-01
  000250 AD3112 60 .50 1982-02-01 1982-03-15
  000250 AD3112 60 .50 1982-12-01 1983-01-01
  000250 AD3112 60 1.00 1983-01-01 1983-02-01
  000250 AD3112 70 .50 1982-02-01 1982-03-15
  000250 AD3112 70 1.00 1982-03-15 1982-08-15
  000250 AD3112 70 .25 1982-08-15 1982-10-15
  000250 AD3112 80 .25 1982-08-15 1982-10-15
  000250 AD3112 80 .50 1982-10-15 1982-12-01
  000250 AD3112 180 .50 1982-08-15 1983-01-01
  000260 AD3113 70 .50 1982-06-15 1982-07-01
  000260 AD3113 70 1.00 1982-07-01 1983-02-01
  000260 AD3113 80 1.00 1982-01-01 1982-03-01
  000260 AD3113 80 .50 1982-03-01 1982-04-15
  000260 AD3113 180 .50 1982-03-01 1982-04-15
  000260 AD3113 180 1.00 1982-04-15 1982-06-01
  000260 AD3113 180 .50 1982-06-01 1982-07-01
  000270 AD3113 60 .50 1982-03-01 1982-04-01
  000270 AD3113 60 1.00 1982-04-01 1982-09-01
  000270 AD3113 60 .25 1982-09-01 1982-10-15
  000270 AD3113 70 .75 1982-09-01 1982-10-15
  000270 AD3113 70 1.00 1982-10-15 1983-02-01
  000270 AD3113 80 1.00 1982-01-01 1982-03-01
  000270 AD3113 80 .50 1982-03-01 1982-04-01
  000030 IF1000 10 .50 1982-06-01 1983-01-01
  000130 IF1000 90 1.00 1982-01-01 1982-10-01
  000130 IF1000 100 .50 1982-10-01 1983-01-01
  000140 IF1000 90 .50 1982-10-01 1983-01-01
  000030 IF2000 10 .50 1982-01-01 1983-01-01
  000140 IF2000 100 1.00 1982-01-01 1982-03-01
  000140 IF2000 100 .50 1982-03-01 1982-07-01
  000140 IF2000 110 .50 1982-03-01 1982-07-01
  000140 IF2000 110 .50 1982-10-01 1983-01-01
  000010 MA2100 10 .50 1982-01-01 1982-11-01
  000110 MA2100 20 1.00 1982-01-01 1982-03-01
  000010 MA2110 10 1.00 1982-01-01 1983-02-01
  000200 MA2111 50 1.00 1982-01-01 1982-06-15
  000200 MA2111 60 1.00 1982-06-15 1983-02-01
  000220 MA2111 40 1.00 1982-01-01 1983-02-01
  000150 MA2112 60 1.00 1982-01-01 1982-07-15
  000150 MA2112 180 1.00 1982-07-15 1983-02-01
  000170 MA2112 60 1.00 1982-01-01 1983-06-01
  000170 MA2112 70 1.00 1982-06-01 1983-02-01
  000190 MA2112 70 1.00 1982-02-01 1982-10-01
  000190 MA2112 80 1.00 1982-10-01 1983-10-01
  000160 MA2113 60 1.00 1982-07-15 1983-02-01
  000170 MA2113 80 1.00 1982-01-01 1983-02-01
  000180 MA2113 70 1.00 1982-04-01 1982-06-15
  000210 MA2113 80 .50 1982-10-01 1983-02-01
  000210 MA2113 180 .50 1982-10-01 1983-02-01
  000050 OP1000 10 .25 1982-01-01 1983-02-01
  000090 OP1010 10 1.00 1982-01-01 1983-02-01
  000280 OP1010 130 1.00 1982-01-01 1983-02-01
  000290 OP1010 130 1.00 1982-01-01 1983-02-01
  000300 OP1010 130 1.00 1982-01-01 1983-02-01
  000310 OP1010 130 1.00 1982-01-01 1983-02-01
  000050 OP2010 10 .75 1982-01-01 1983-02-01
  000100 OP2010 10 1.00 1982-01-01 1983-02-01
  000320 OP2011 140 .75 1982-01-01 1983-02-01
  000320 OP2011 150 .25 1982-01-01 1983-02-01
  000330 OP2012 140 .25 1982-01-01 1983-02-01
  000330 OP2012 160 .75 1982-01-01 1983-02-01
  000340 OP2013 140 .50 1982-01-01 1983-02-01
  000340 OP2013 170 .50 1982-01-01 1983-02-01
  000020 PL2100 30 1.00 1982-01-01 1982-09-15

Relationship of EMP_ACT to Other Tables

The EMP_ACT table is a dependent of:


IN_TRAY Table

The IN_TRAY table contains a person's note log.
Name: RECEIVED SOURCE SUBJECT NOTE_TEXT
Type: timestamp not null char(8) not null char(64) varchar(4000)
Desc: Date and time note was received User id of person who sent note Brief description The text of the note
Values: 1965-01-01-07.00.00 SQLDBA English Here is a note from your DBA.


PROJECT Table

The PROJECT table describes each project that the business is currently undertaking. Data contained in each row includes the project number, name, person responsible, and schedule dates as shown below.
Name: PROJNO PROJNAME DEPTNO RESPEMP PRSTAFF PRSTDATE PRENDATE MAJPROJ
Type: char(6) not null varchar(24) not null char(3) not null char(6) not null dec(5,2) date date char(6)
Desc: Project number Project name Department responsible Employee responsible Estimated mean staffing Estimated start date Estimated end date Major project, for a subproject
Values: AD3100 ADMIN SERVICES D01 000010 6.5 1982-01-01 1983-02-01 ?
  AD3110 GENERAL ADMIN SYSTEMS D21 000070 6 1982-01-01 1983-02-01 AD3100
  AD3111 PAYROLL PROGRAMMING D21 000230 2 1982-01-01 1983-02-01 AD3110
  AD3112 PERSONNEL PROGRAMMING D21 000250 1 1982-01-01 1983-02-01 AD3110
  AD3113 ACCOUNT PROGRAMMING D21 000270 2 1982-01-01 1983-02-01 AD3110
  IF1000 QUERY SERVICES C01 000030 2 1982-01-01 1983-02-01 ?
  IF2000 USER EDUCATION C01 000030 1 1982-01-01 1983-02-01 ?
  MA2100 WELD LINE AUTOMATION D01 000010 12 1982-01-01 1983-02-01 ?
  MA2110 W L PROGRAMMING D11 000060 9 1982-01-01 1983-02-01 MA2100
  MA2111 W L PROGRAM DESIGN D11 000220 2 1982-01-01 1982-12-01 MA2110
  MA2112 W L ROBOT DESIGN D11 000150 3 1982-01-01 1982-12-01 MA2110
  MA2113 W L PROD CONT PROGS D11 000160 3 1982-02-15 1982-12-01 MA2110
  OP1000 OPERATION SUPPORT E01 000050 6 1982-01-01 1983-02-01 ?
  OP1010 OPERATION E11 000090 5 1982-01-01 1983-02-01 OP1000
  OP2000 GEN SYSTEMS SERVICES E01 000050 5 1982-01-01 1983-02-01 ?
  OP2010 SYSTEMS SUPPORT E21 000100 4 1982-01-01 1983-02-01 OP2000
  OP2011 SCP SYSTEMS SUPPORT E21 000320 1 1982-01-01 1983-02-01 OP2010
  OP2012 APPLICATIONS SUPPORT E21 000330 1 1982-01-01 1983-02-01 OP2010
  OP2013 DB/DC SUPPORT E21 000340 1 1982-01-01 1983-02-01 OP2010
  PL2100 WELD LINE PLANNING B01 000020 1 1982-01-01 1982-09-15 MA2100

Relationship of PROJECT to Other Tables

PROJECT is a parent of the PROJ_ACT table.

PROJECT is a dependent of:


PROJ_ACT Table

The PROJ_ACT table lists the activities performed for each project. The table contains information on the start and completion dates of the project activity as well as staffing requirements as shown below.
Name: PROJNO ACTNO ACSTAFF ACSTDATE ACENDATE
Type: char(6) not null smallint not null decimal(5,2) date not null date
Desc: Project number Activity number Estimated mean staffing for activity Estimated start date for activity Estimated end date for activity
Values: AD3100 10 0.50 1982-01-01 1982-07-01
  AD3110 10 1.00 1982-01-01 1983-01-01
  AD3111 60 0.50 1982-03-15 1982-04-15
  AD3111 60 0.80 1982-01-01 1982-04-15
  AD3111 70 0.50 1982-03-15 1982-10-15
  AD3111 70 1.50 1982-02-15 1982-10-15
  AD3111 80 1.00 1982-09-15 1983-01-01
  AD3111 80 1.25 1982-04-15 1983-01-15
  AD3111 180 1.00 1982-10-15 1983-01-15
  AD3112 60 0.50 1982-02-01 1982-03-15
  AD3112 60 0.75 1982-01-01 1982-05-15
  AD3112 60 0.75 1982-12-01 1983-01-01
  AD3112 60 1.00 1983-01-01 1983-02-01
  AD3112 70 0.25 1982-08-15 1982-10-15
  AD3112 70 0.50 1982-02-01 1982-03-15
  AD3112 70 0.75 1982-01-01 1982-10-15
  AD3112 70 1.00 1982-03-15 1982-08-15
  AD3112 80 0.35 1982-08-15 1982-12-01
  AD3112 80 0.50 1982-10-15 1982-12-01
  AD3112 180 0.50 1982-08-15 1983-01-01
  AD3113 60 0.25 1982-09-01 1982-10-15
  AD3113 60 0.75 1982-03-01 1982-10-15
  AD3113 60 1.00 1982-04-01 1982-09-01
  AD3113 70 0.50 1982-06-15 1982-07-01
  AD3113 70 0.75 1982-09-01 1982-10-15
  AD3113 70 1.00 1982-07-01 1983-02-01
  AD3113 70 1.00 1982-10-15 1983-02-01
  AD3113 70 1.25 1982-06-01 1982-12-15
  AD3113 80 0.50 1982-03-01 1982-04-15
  AD3113 80 1.75 1982-01-01 1982-04-15
  AD3113 180 0.50 1982-06-01 1982-07-01
  AD3113 180 0.75 1982-03-01 1982-07-01
  AD3113 180 1.00 1982-04-15 1982-06-01
  IF1000 10 0.50 1982-01-01 1983-01-01
  IF1000 10 0.50 1982-06-01 1983-01-01
  IF1000 90 0.50 1982-10-01 1983-01-01
  IF1000 90 1.00 1982-01-01 1983-01-01
  IF1000 100 0.50 1982-01-01 1983-01-01
  IF2000 10 0.50 1982-01-01 1983-01-01
  IF2000 100 0.50 1982-03-01 1982-07-01
  IF2000 100 0.75 1982-01-01 1982-07-01
  IF2000 110 0.50 1982-03-01 1982-07-01
  IF2000 110 0.50 1982-10-01 1983-01-01
  MA2100 10 0.50 1982-01-01 1982-11-01
  MA2100 20 1.00 1982-01-01 1982-03-01
  MA2110 10 1.00 1982-01-01 1983-02-01
  MA2111 40 1.00 1982-01-01 1983-02-01
  MA2111 50 1.00 1982-01-01 1092-06-01
  MA2111 60 1.00 1982-06-01 1983-02-01
  MA2111 60 1.00 1982-06-15 1983-02-01
  MA2112 60 2.00 1982-01-01 1982-07-01
  MA2112 70 1.00 1982-02-01 1982-10-01
  MA2112 70 1.00 1982-06-01 1983-02-01
  MA2112 70 1.50 1982-02-15 1983-02-01
  MA2112 80 1.00 1982-10-01 1983-10-01
  MA2112 180 1.00 1982-07-01 1983-02-01
  MA2112 180 1.00 1982-07-15 1983-02-01
  MA2113 60 1.00 1982-02-15 1982-09-01
  MA2113 60 1.00 1982-07-15 1983-02-01
  MA2113 70 2.00 1982-04-01 1983-12-15
  MA2113 80 1.00 1982-01-01 1983-02-01
  MA2113 80 1.50 1982-09-01 1983-02-01
  MA2113 80 0.50 1982-10-01 1983-02-01
  MA2113 180 0.50 1982-10-01 1983-01-01
  OP1000 10 0.25 1982-01-01 1983-02-01
  OP1010 10 1.00 1982-01-01 1983-02-01
  OP1010 130 4.00 1982-01-01 1983-02-01
  OP2000 50 0.75 1982-01-01 1983-02-01
  OP2010 10 1.00 1982-01-01 1983-02-01
  OP2011 140 0.75 1982-01-01 1983-02-01
  OP2011 150 0.25 1982-01-01 1983-02-01
  OP2012 140 0.25 1982-01-01 1983-02-01
  OP2012 160 0.75 1982-01-01 1983-02-01
  OP2013 140 0.50 1982-01-01 1983-02-01
  OP2013 170 0.50 1982-01-01 1983-02-01
  PL2100 30 1.00 1982-01-01 1982-09-15
  PL2100 30 1.00 1982-02-01 1982-09-01

Relationship of PROJ_ACT to Other Tables

PROJ_ACT is a parent of the EMP_ACT table.

It is a dependent of:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]