This page provides answers for the SQL Problem sets.
SQL Exercise Set #4 | ||
1. Insert yourself as a new employee into the EMP table. | insert into emp(empno, ename, job, mgr, hiredate,
sal, comm, deptno)
values(8120, "JONES", "Goddess", 8120, #01/01/2003#, 500000, 5000, 10) |
|
3. How can you insert other rows into the EMP table prompting the operator for the employee number, department number, hire date, and employee name. | insert into emp(empno, ename, job, mgr, hiredate,
sal, comm, deptno)
values([Employee Number: ], [Employee Name: ], "Goddess", 8120, [HireDate: ], 500000, 5000, [Department Number: ]) |
|
4. Add a new department into the DEPT table with a department number of 99, location of Maui, and a department name of Education. | insert into DEPT(DeptNo,Dname,Loc)
values(99,"Maui","Education") |
|
5. Update your own employee data by giving yourself a $1000 per month raise. | update emp set sal=[sal]+1000
where ename="JONES" and empno=8120 |
|
6. Delete yourself from the EMP table. | delete from emp where ename="JONES" and empno=8120 | |
7. Re-create the query named EMP_DEPTNO_TEN. |
|
|
8. Save the query in the database. | SEE ANSW 7 (Clicked the disk icon to save query, naming it "EMP_DEPTNO_TEN") | |
9. Update KING’s department number from 10 to 20 using this query. |
|
|
10. Use a query to see if KING is still in your view or query. |
|
|
11. Delete (or at least don't save) the query. | Closed the query window, answering "no" when prompted to save changes. | |
12. Change KING’s department number back to 10. | update emp set deptno = 10 where ename="KING" | |
13. How can you force EMP_DEPTNO_TEN to validate that a Department exists before updating new changes. |
|
|
14. What happens when you update KING’s department from 10 to 20? | The record saves without incident since department 20 exists in the dept table. | |
15. Try to insert a duplicate employee into the EMP table to test the index created in section 3. | Received the following error message:
|
|
16. Insert several new departments and see what new sequence numbers are created. How can you make deptno go up in a series of 10s. | Because it is not an autonumber field, no sequence numbers were automatically created for the deptno field. Instead, the value of 0 was placed by default into the field. However, you can add another autonumber field in a Data Definition query to accomplish something like this. The sql would be as follows: alter table dept add column deptnumber counter (100,10) constraint pkDept PRIMARY KEY The result of this would be that all new numbers in the deptnumber field would be added in increments of ten, starting at 100 (since we added dept 99 in a previous question). |
|
17. Enter a query to observe your newly inserted departments. | select deptno as Department from dept where deptno < 100
UNION select deptnumber as Department from dept where deptnumber > =100; The result is: |
SQL Problem Sets |