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 101 102 103 104 105 106 114 118

EMP_FNAME John David June Anne Alice William Annelise default value

EMP_LNAME News Senior Arbough Ramoras Johnson Smithfield Jones Frommer

JOB_CLASS DBD SYA EEG SYA DBD PRG

HIREDATE 1-NOV-78 3-OCT-88 23-JUN-99 30-FEB-92 15-AUG-95 31-OCT-02

JOB

JOB_CODE APD DBD EEG GSP PRG SYA

JOB_CLASS Application Designer Database Designer Elec. Engineer General Support Programmer Systems Analyst

CHG_HOUR $48.10 $105.00 $84.50 $18.36 $37.75 $96.75

PROJECT

PROJ PROJ

_NUM _NAME 15 18 Evergreen Amber Wave .

All employees must have a last name. then a default of "unknown" will be entered.7 24.3 A) Create/Alter/Drop Table Commands: -1) All employees may or may not be given a job_class. All employees must have a hiredate.PROJ_EMP PROJ EMP _NUM _NUM HOUR 15 15 15 18 18 103 101 105 114 118 23.4 35. and the last name can not be repeated by other employees. Job_class can be repeated in the employee table. If no first name is specified when inserting an employee record. Complete the data dictionary below: Table: EMPLOYEE Column Type Len gth Emp_Num PK FK Required Not Null Unique Validation /Check Default emp_fname emp_lname Job_Class .6 25. and the hiredate must be >= 1-Jan-90.8 19.

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

Column Type Len gth Emp_Num int PK PK FK Required Not Null Unique Validation /Check Default emp_fname char 20 unknown emp_lname char 20 NN unique Job_Class char 3 job (job_code) hiredate date NN >=1/1/1990 .0. Also implement the following constraints. Create the EMP table from the sample data on the previous page. Complete the data dictionary below: Table: JOB Column Type Len gth job_code PK FK Required Not Null Unique Validation /Check Default job_class chg_hour 1.

2 >=15 15 . Also implement the following constraints. Column Type Len gth job_code char 3 PK PK FK Required Not Null Unique Validation /Check Default job_class char 30 chg_hour decimal 5. Create the JOB table from the sample data on the previous page.2.

6. Add a constraint that always requires a value entered into the CHG_HOUR column. 5. Add a constraint to the JOB table that will ensure all CHG_HOUR data is >= 25. . 4. 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.3. Add a new attribute to the JOB table named OvertimeCharge that must always have a value.

Drop the constraint CHARGE_CK from the CHG_HOUR column. 8. Change the CHG_HOUR column to store numbers up to 12 digits in length (including decimal points). 10. . Drop the chg_hour column and all of it's data from the job table. Drop the column named OvertimeCharge from the JOB table.7. 9.

12. Insert the last 3 rows shown into the EMP table.11. . B) Data Manipulation Commands: 1. Drop the table emp and all rows of it's data. Remove the job table and all of it's data.

Update the employee fname to Jim instead of James for employee 118 3. Remove the row from the job table for job code PRG .2. Update the Database Designer chg_hour value by 10% 4.

Remove the emp table and all of it's data . 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.5.

C) Select Commands: 1. 2. Same question as above. Show the employee first and last names and their job class description and hourly charge. but only show the records where the chg_hour is <100 .

3. Create a view called: WORK_INFO which will select the hours worked and lastname and hiredate for all employees hired before 1-jan-02. 4. Select the hours worked and lastname and hiredate for all employees. .

Save this select statement as a view called: EMP_PROJECTS .5. Select employee fname and lname and all projects that they are working on.

6. Select all project names and job class descriptions that the project requires. Save this select statement as a view called: EMP_JOB_SKILLS . Select employee fname and lname and all projects that they are working on for project 7. 18.

Select customer first and last name. Save this statement as a view called: DATABASE_DESIGNERS 9. . Select all project names and job class descriptions that the project requires for only the job code of DBD. credit limit. and salesrep first and last name where the credit limit is >= 1500.8.

43897.419 8/.4:23.9.1742904-9.2.39#*174290* &#.4:233.*4:7.20/ .4:2394894703:2-078:594/983039 3.70174290 9.3/.4:23  74590.  .07920.:/3 /0.-0  .54398                                              74590.-0  74590.3090* &#.

  .3/.3/.9.419 8/.  745909.9.35:.                                  #024.-0.3/8          3807990.0904-9.943422.9..8974884339490!9.748419 8/.-0025.-0  .

209423890.                                              &5/..-01474-.4/0!# .909002540013./41.208147025400 &5/.9090.:0-  #024.090741742904-9.-.*4:7.9.8008307.

9.419 8/. #024.                                              #024. .908-01470 .090 9.9.09002540081742900254009.3   #024.3/.419 8/.-0.-00709070/.-0.0900259.3/.

.9422.75943.3/.208.3/4:7.206:08943.893.     $00.47/807090.3/8                                         $4900254001789.3/9074-.*4:78  ..8.-4.0 -:943849070.70  $.88/08.

20.90147.0.3/ 70/.3        ..800..0254008    70.90147.3/.893.893.3/.9904:78470/.20.9904:78470/.                                      $00.025400870/-01470 .3/70/.90.0/ #* .

3/3.0/!*!# %$                       ..8.989.20.902540013.7047343 $.0.902039..989..3/.098 800.5740.20.990.                       $00.

.9706:708 $.               $00.9.20.8.0.098   800.0/!* *$$                         $00.20.989.93..5740.9905740.70473431475740.5740.208.7594389..989.88/08..3/.3/3.990.9 .3/4-.902540013.902039.

0/%$*$#$                               $00.88/08.208.3/8.0.9706:7081474390 4-.7594389.:8942071789.893..3/.3/4-.9..70/9298          .087051789.902039.4/041 $.  $00.9.9905740.3/.893.20 .70/929 .93.09889..20070 90.5740..8.

Sign up to vote on this title
UsefulNot useful