New month, new goals. Your help keeps the project moving forward. 🖥️ Support sqltest →
SQL code copied to buffer

Employee database (Firebird): schema, tables and SQL exercises

Employee is the sample database that comes with Firebird: employees, departments, jobs, projects, customers and sales of a small company. On SQLtest.online you can query it right in your browser: solve exercises with automatic checking and run your own queries in the playground, with nothing to install.

  • 10 tables and 1 view
  • 42 employees
  • 21 departments
  • 33 SQL exercises

What is Employee

Employee is the classic example database of Firebird, inherited from InterBase. It describes a small international company: its department tree, staff and salary history, projects with budgets, and sales to customers.

The database is small, so results are easy to check by eye, but it has interesting relationships: a department hierarchy, a composite foreign key from employees to jobs and many-to-many links between employees and projects. It is also the place to practice the Firebird SQL dialect.

ER diagram

The diagram shows the Employee tables and the foreign keys between them. Click it to open the full-size version.

ER diagram of the Employee database

What's inside

The tables fall into three groups.

Staff

EMPLOYEE, DEPARTMENT (each department has a parent), JOB and SALARY_HISTORY.

Projects

PROJECT, the link table EMPLOYEE_PROJECT and the yearly budgets in PROJ_DEPT_BUDGET.

Sales

CUSTOMER, SALES (purchase orders) and COUNTRY with currencies.

The key thing to remember: a job is identified by three columns at once (code, grade and country), so joining EMPLOYEE to JOB needs all three. The view PHONE_LIST combines employees with their department phone numbers.

How much data the tables hold:

TableRowsContents
EMPLOYEE42employees
DEPARTMENT21departments
JOB31jobs and salary ranges
SALARY_HISTORY49salary changes
PROJECT6projects
EMPLOYEE_PROJECT28employees ↔ projects
PROJ_DEPT_BUDGET24project budgets by department and year
CUSTOMER15customers
SALES33purchase orders
COUNTRY16countries and currencies

Table structure

Click a table to see its columns, a sample row and its keys.

List of tables

COUNTRY - countries table.
  • COUNTRYName of the country
  • CURRENCYCurrency used in the country
COUNTRY CURRENCY
USA Dollar
JOB - company's staff schedule.
  • JOB_CODEJob code
  • JOB_GRADEJob grade
  • JOB_COUNTRYCountry associated with the job
  • JOB_TITLEJob title
  • MIN_SALARYMinimum salary for the job
  • MAX_SALARYMaximum salary for the job
  • JOB_REQUIREMENTJob requirements
  • LANGUAGE_REQLanguage requirements
JOB_CODE JOB_GRADE JOB_COUNTRY JOB_TITLE MIN_SALARY MAX_SALARY JOB_REQUIREMENT LANGUAGE_REQ
CEO 1 USA Chief Executive Officer 130000.00 250000.00 No specific requirements. [null]
  • FOREIGN KEY (JOB_COUNTRY) REFERENCES COUNTRY(COUNTRY)
DEPARTMENT - company divisions.
  • DEPT_NODepartment number
  • DEPARTMENTDepartment name
  • HEAD_DEPTHead department (can be null)
  • MNGR_NOManager number
  • BUDGETDepartment budget
  • LOCATIONDepartment location
  • PHONE_NOPhone number for the department
DEPT_NO DEPARTMENT HEAD_DEPT MNGR_NO BUDGET LOCATION PHONE_NO
000 Corporate Office [null] 105 1000000.00 Monterey (408) 555-1234
  • FOREIGN KEY (HEAD_DEPT) REFERENCES DEPARTMENT(DEPT_NO)
EMPLOYEE - list of employees.
  • EMP_NOEmployee number
  • FIRST_NAMEFirst name of the employee
  • LAST_NAMELast name of the employee
  • PHONE_EXTPhone extension for the employee
  • HIRE_DATEDate of employee's hire
  • DEPT_NODepartment number
  • JOB_CODEJob code for the employee
  • JOB_GRADEJob grade for the employee
  • JOB_COUNTRYCountry associated with the employee's job
  • SALARYSalary of the employee
  • FULL_NAMEFull name of the employee
EMP_NO FIRST_NAME LAST_NAME PHONE_EXT HIRE_DATE DEPT_NO JOB_CODE JOB_GRADE JOB_COUNTRY SALARY FULL_NAME
2 Robert Nelson 250 1988-12-28 00:00:00 600 VP 2 USA 105900.00 Nelson, Robert
  • FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO)
  • FOREIGN KEY (JOB_CODE) REFERENCES JOB(JOB_CODE)
PROJECT - list of projects.
  • PROJ_IDProject ID
  • PROJ_NAMEProject name
  • PROJ_DESCProject description
  • TEAM_LEADERTeam leader for the project
  • PRODUCTProduct associated with the project
PROJ_ID PROJ_NAME PROJ_DESC TEAM_LEADER PRODUCT
VBASE Video Database Development of a video database management system for managing video distribution on demand. 45 software
  • FOREIGN KEY (TEAM_LEADER) REFERENCES EMPLOYEE(EMP_NO)
EMPLOYEE_PROJECT - employee-project mapping.
  • EMP_NOEmployee number
  • PROJ_IDProject ID
EMP_NO PROJ_ID
144 DGPII
  • FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE(EMP_NO)
  • FOREIGN KEY (PROJ_ID) REFERENCES PROJECT(PROJ_ID)
PROJ_DEPT_BUDGET - project budgets.
  • FISCAL_YEARFiscal year
  • PROJ_IDProject ID
  • DEPT_NODepartment number
  • QUART_HEAD_CNTQuarter headcount (can be null)
  • PROJECTED_BUDGETProjected budget for the fiscal year
FISCAL_YEAR PROJ_ID DEPT_NO QUART_HEAD_CNT PROJECTED_BUDGET
1994 GUIDE 100 [null] 200000.00
  • FOREIGN KEY (PROJ_ID) REFERENCES PROJECT(PROJ_ID)
  • FOREIGN KEY (DEPT_NO) REFERENCES DEPARTMENT(DEPT_NO)
SALARY_HISTORY - history of employee salary changes.
  • EMP_NOEmployee number
  • CHANGE_DATEDate of salary change
  • UPDATER_IDUpdater ID
  • OLD_SALARYPrevious salary
  • PERCENT_CHANGEPercentage change in salary
  • NEW_SALARYNew salary after the change
EMP_NO CHANGE_DATE UPDATER_ID OLD_SALARY PERCENT_CHANGE NEW_SALARY
28 1992-12-15 00:00:00 admin2 20000.00 10.000000 22000.000000
  • FOREIGN KEY (EMP_NO) REFERENCES EMPLOYEE(EMP_NO)
CUSTOMER - company clients.
  • CUST_NOCustomer number
  • CUSTOMERCustomer name
  • CONTACT_FIRSTFirst name of the contact person
  • CONTACT_LASTLast name of the contact person
  • PHONE_NOPhone number for the customer
  • ADDRESS_LINE1 Address line 1
  • ADDRESS_LINE2Address line 2 (can be null)
  • CITYCity of the customer
  • STATE_PROVINCEState or province of the customer
  • COUNTRYCountry of the customer
  • POSTAL_CODEPostal code of the customer
  • ON_HOLDOn hold status (can be null)
CUST_NO CUSTOMER CONTACT_FIRST CONTACT_LAST PHONE_NO ADDRESS_LINE1 ADDRESS_LINE2 CITY STATE_PROVINCE COUNTRY POSTAL_CODE ON_HOLD
1001 Signature Design Dale J. Little (619) 530-2710 15500 Pacific Heights Blvd. [null] San Diego CA USA 92121 [null]
  • FOREIGN KEY (COUNTRY) REFERENCES COUNTRY(COUNTRY)
SALES - list of sales.
  • PO_NUMBERPurchase order number
  • CUST_NOCustomer number associated with the order
  • SALES_REPSales representative number
  • ORDER_STATUSOrder status
  • ORDER_DATEDate of the order
  • SHIP_DATEDate of shipment
  • DATE_NEEDEDDate needed (can be null)
  • PAIDPayment status
  • QTY_ORDEREDQuantity ordered
  • TOTAL_VALUETotal value of the order
  • DISCOUNTDiscount applied
  • ITEM_TYPEType of item in the order
  • AGEDAged value
PO_NUMBER CUST_NO SALES_REP ORDER_STATUS ORDER_DATE SHIP_DATE DATE_NEEDED PAID QTY_ORDERED TOTAL_VALUE DISCOUNT ITEM_TYPE AGED
V91E0210 1004 11 shipped 1991-03-04 00:00:00 1991-03-05 00:00:00 [null] y 10 5000.00 0.100000 hardware 1.000000000
  • FOREIGN KEY (CUST_NO) REFERENCES CUSTOMER(CUST_NO)
  • FOREIGN KEY (SALES_REP) REFERENCES EMPLOYEE(EMP_NO)

Below is a list of this DB views:

PHONE_LIST - employee phone list view.
  • EMP_NOEmployee number
  • FIRST_NAMEFirst name of the employee
  • LAST_NAMELast name of the employee
  • PHONE_EXTPhone extension for the employee
  • LOCATIONDepartment location
  • PHONE_NODepartment phone number
EMP_NO FIRST_NAME LAST_NAME PHONE_EXT LOCATION PHONE_NO
2 Robert Nelson 250 Monterey (408) 555-1234

Sample queries

These queries show how the data is connected. Copy any of them and run it in the playground.

An employee, department and job: a join on a composite key of three columns.

SELECT FIRST 3 e.FIRST_NAME, e.LAST_NAME, d.DEPARTMENT, j.JOB_TITLE
FROM EMPLOYEE e
JOIN DEPARTMENT d ON d.DEPT_NO = e.DEPT_NO
JOIN JOB j ON j.JOB_CODE = e.JOB_CODE
          AND j.JOB_GRADE = e.JOB_GRADE
          AND j.JOB_COUNTRY = e.JOB_COUNTRY
ORDER BY e.EMP_NO;
FIRST_NAMELAST_NAMEDEPARTMENTJOB_TITLE
RobertNelsonEngineeringVice President
BruceYoungSoftware DevelopmentEngineer
KimLambertField Office: East CoastEngineer

Orders and customers: Firebird uses FIRST n to limit rows.

SELECT FIRST 3 s.PO_NUMBER, c.CUSTOMER, s.ORDER_DATE, s.TOTAL_VALUE
FROM SALES s
JOIN CUSTOMER c ON c.CUST_NO = s.CUST_NO
ORDER BY s.ORDER_DATE;
PO_NUMBERCUSTOMERORDER_DATETOTAL_VALUE
V91E0210Central Bank1991-03-04 00:00:005000.00
V92J1003MPM Corporation1992-07-26 00:00:002985.00
V92E0340Central Bank1992-10-15 00:00:0070000.00

SQL exercises by topic

There are 33 exercises on the Employee database, from simple selections to window functions and data changes. Solutions are checked automatically on a real Firebird server. The number on the right is how many exercises a topic has; the colored dots show its difficulty range.

Where to start

The first exercises on the Employee database:

  1. List Departments
  2. Find non-Dollar/Euro countries
  3. Sub-departments List (JOIN)
  4. List of Sub-Departments
  5. Identify Foreign Employees
  6. Find Employees by Department
  7. Retrieve Employee Salary
  8. Employees with High Salaries
  9. Employees with Above-Average Salaries
  10. Find the Managed Department

All Employee exercises →

FAQ

Do I need to install Firebird to use the Employee database?

No. The exercises and the playground on SQLtest.online run your queries on our servers, so a browser is all you need. In the playground, Employee is available on Firebird 4.0.

Where does the Employee database come from?

It ships with Firebird as an example database (employee.fdb) and dates back to InterBase, the predecessor of Firebird.

How is Firebird SQL different?

Most of standard SQL works as usual. Differences you will meet first: FIRST n / SKIP n or FETCH FIRST n ROWS ONLY to limit rows, and uppercase object names.