Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create the DEPARTMENT table based on the following table instance chart. Ente

ID: 3913887 • Letter: 1

Question

1. Create the DEPARTMENT table based on the following table instance chart. Enter
the syntax in a script called p10q1.sql, then execute the script to create the table.
Confirm that the table is created.

Name Null? Type
---------- -------- ----------
ID NUMBER(7)
NAME   VARCHAR2(25)

2. Populate the DEPARTMENT table with data from the DEPT table. Include only
columns that you need.

3. Create the EMPLOYEE table based on the following table instance chart. Enter the
syntax in a script called p10q3.sql, and then execute the script to create the table.
Confirm that the table is created.

4. Modify the EMPLOYEE table to allow for longer employee last names. Confirm your
modification.

5. Confirm that both the DEPARTMENT and EMPLOYEE tables are stored in the data
dictionary. (Hint: USER_TABLES)

6. Create the EMPLOYEE2 table based on the structure of the EMP table. Include only
the EMPNO, ENAME, and DEPTNO columns. Name the columns in your new table
ID, LAST_NAME, and DEPT_ID, respectively.

Column Name Key Type Nulls/Unique FK Table FK Col umn Datatype Length Id Name Number Varchar2 25

Explanation / Answer

SOLUTIONS

1)
Sol) create table department(ID number(7),NAME varchar2(25));

2)
Sol) INSERT INTO department
SELECT id, name
FROM dept;

3)
Sol) create table employee(ID NUMBER(7),LAST_NAME VARCHAR2(25),FIRST_NAME VARCHAR2(25),DEPT_ID NUMBER(7));

4)
Sol) ALTER TABLE employee modify LAST_NAME VARCHAR2(50);

5)
Sol) SELECT MY_TABLE FROM USER_TABLES WHERE MY_TABLE IN('DEPT','EMPLOYEE');

6)
Sol) CREATE TABLE EMPLOYEES2 AS SELECT EMPNO ID,ENAME LAST_NAME,DEPTNO DEPT_ID FROM EMP