Sie sind auf Seite 1von 5

DBS201

SQL Practice Problems


Sample questions and SQL answers:

Click here for answers Answers

Use the following sample tables, data, and constraints to answers the questions that follow:

EMP
EMP_NUM

EMP_FNAME

EMP_LNAME

JOB_CLASS

HIREDATE

101

John

News

DBD

1-NOV-78

102

David

Senior

SYA

3-OCT-88

103

June

Arbough

EEG

23-JUN-99

104

Anne

Ramoras

SYA

30-FEB-92

105

Alice

Johnson

DBD

15-AUG-95

106

William

Smithfield

PRG

31-OCT-02

114

Annelise

Jones

118

default value

Frommer

JOB
JOB_CODE

JOB_CLASS

CHG_HOUR

APD

Application Designer

DBD

Database Designer

EEG

Elec. Engineer

$84.50

GSP

General Support

$18.36

PRG

Programmer

$37.75

SYA

Systems Analyst

$96.75

PROJECT
PROJ PROJ
_NUM _NAME
15

Evergreen

18

Amber Wave

PROJ_EMP

$48.10
$105.00

PROJ

EMP

_NUM _NUM

HOUR

15

103

23.8

15

101

19.4

15

105

35.7

18

114

24.6

18

118

25.3

A) Create/Alter/Drop Table Commands (Data Definition Language):


1.

All employees may or may not be given a job_class. Job_class can be repeated in the
employee table. If no first name is specified when inserting an employee record, then a default
of "unknown" will be entered. All employees must have a last name, a hiredate, and the
hiredate must be >= 1-Jan-1990.

Complete the data dictionary below: Table: EMPLOYEE


Column

Type

Len
gth

Emp_Num

emp_fname

emp_lname

Job_Class

hiredate

PK

FK

Required
Not Null

Unique

Validation
/Check

Default

Complete the data dictionary below: Table: JOB


All chg_hour will default to a value of $15/hour if no value is specified during the insert. If a
value is specified, then it must be >= $15.

Column

Type

Len

PK

FK

gth

Required

Unique

Not Null

Validation

Default

/Check

job_code

job_class

chg_hour

3.
Create the EMP table from the sample data on the previous page. Also implement the
following constraints.
Column

Type

Len

PK

FK

gth
Emp_Num

int

emp_fname

char

20

emp_lname

char

20

Job_Class

char

Required

Unique

Not Null

Validation

Default

/Check

PK

unknown

NN

unique

job
(job_code)

hiredate

date

NN

>=1/1/1990

4.
Create the JOB table from the sample data on the previous page. Also implement the
following constraints.
Column

Type

Len

PK

gth
job_code

char

job_class

char

30

chg_hour

decimal

5,2

FK

Required
Not Null

Unique

Validation

Default

/Check

PK

>=15

15

5.

Add a new attribute to the JOB table named OvertimeCharge that must always have a value.

6.

Add a constraint to the JOB table that will ensure all CHG_HOUR data is >= 25.

7.
Add a constraint that will add the value NA to all JOB_CLASS columns if no value is
specified when the record is inserted into the table.
8.

Add a constraint that always requires a value entered into the CHG_HOUR column.

9.
Change the CHG_HOUR column to store numbers up to 12 digits in length (including
decimal points).
10.

Drop the constraint CHARGE_CK from the CHG_HOUR column.

11.

Drop the column named OvertimeCharge from the JOB table.

12.

Drop the chg_hour column and all of it's data from the job table.

13.

Remove the job table and all of it's data.

14.

Drop the table emp and all rows of it's data.

B) Data Manipulation Commands:


1.

Insert the last 3 rows shown into the EMP table.

2.

Update the employee fname to Jim instead of James for employee 118

3.

Update the Database Designer chg_hour value by 10%

4.

Remove the row from the job table for job code PRG

5.

Remove the JOB table and all of it's data

6.

Remove the employees from the employee table where the hiredate is before 1-Jan-90

7.

Remove the emp table and all of it's data

C) Select Commands:
1.

Show the employee first and last names and their job class description and hourly charge.

2.

Same question as above, but only show the records where the chg_hour is <100

3.

Select the hours worked and lastname and hiredate for all employees.

4.
Create a view called: WORK_INFO which will select the hours worked and lastname and
hiredate for all employees hired before 1-jan-02.
5.
Select employee fname and lname and all projects that they are working on. Save this select
statement as a view called: EMP_PROJECTS
6.

Select employee fname and lname for every person working on project 18.

7.
Select all project names and job class descriptions that the project requires. Save this select
statement as a view called: EMP_JOB_SKILLS
8.

Select all project names and job class descriptions that the project requires for only the job
code of DBD. Save this statement as a view called: DATABASE_DESIGNERS

9.
Select customer first and last name, credit limit, and salesrep first and last name where the
credit limit is >= 1500.
Answers

Das könnte Ihnen auch gefallen