SQL Class Exercise: Table Update
Objective: Apply insert, update and delete operations to modify the employee
table. Table specifications and data are linked to the course web page.
0. Use the show create table schema.table_name command to list the structure
of the employee table.
1. Select yourSchema.employee to project all data in key order.
2. By default MySQL runs in autocommit mode. Issue a START TRANSACTION command
before a series of update commands that may be committed or rolled back.
ROLLBACK will "undo" commands given in the transaction. COMMIT will make
the work final and complete the transaction.
3. Inserting Data:
a. Enter a row for empno 8000, ename 'Brown', job 'Analyst', manager
(NULL), hiredate '2013-06-10', salary (DEFAULT).
b. Store another row including only values for primary key (8001), foreign
key(use some manager's empno for this value), and for any columns having
a NOT NULL constraint.
c. Prepare a single insert statement for entering values for two employees:
empno ename job manager hiredate salary
8002 Gray NULL 7566 2013-06-11 3900.00
8003 Green manager 7839 2013-06-11 4400.00
4. Modifying Data:
a. For Employee 8001, set job to 'MANAGER' and the manager column value to
7839 (do this with a single UPDATE statement).
b. For any employees having a NULL value in salary, set salary to 1.00.
c. Increase the salary for all managers by 10%.
5. Deleting Data:
a. Delete Employee 7369 from the Employee table.
b. Delete all Employees hired during the year 2013.
6. Query your updated table projecting all columns with rows ordered by key.
7. Issue a rollback, then query again to show the table has been restored.
_____________________________________________________________________________
Table Column dataType Constraint
Employee empno int(4) primary key
ename char(10) not null and unique
job varchar(9) default null
manager decimal(4) (recursive) foreign key
hireDate date default null*
salary decimal(7,2) default 1.00