You are on page 1of 8

Oracle Database and Commands

Accessing Spiffy Manufacturing Company Database Six tables for the Spiffy Manufacturing Company have been created already. These six tables are, Employee Table (emp) 42 rows Department Table (dept) 14 rows New Department Table (newdept) 14 rows Project Table (proj) 20 rows Project-Activity Table (proj_act) 77 rows Employee-to-Project-Activity Table (emp_proj_act) 74 rows Detailed table descriptions are as follows,

Employee Table
The employee table contains information about each employee in the sample company (Spiffy Manufacturing Company). Content

Co l 1 2 3 4 5 6

Column Name And Data Type EMPNO CHAR(6) FIRSTNAME VARCHAR(12) MIDINIT CHAR(1) LASTNAME VARCHAR(15) WORKDEPT CHAR(3) PHONE CHAR(4)

Nulls Allowe d No No No No No Yes

Description Employee number (unique ID) First name of employee Middle initial of employee Last name of employee ID of the department in which the employee is working Employee telephone number

7 8 9 10 11 12

HIREDATE DATE JOB VARCHAR(9) EDUCATION SMALLINT SEX CHAR(1) BIRTHDATE DATE SALARY DECIMAL(9,2)

Yes Yes Yes Yes Yes Yes

Date of hire (YYYY-MM-DD) Code indicating the job held by the employee Number of years of formal education Sex of the employee (where M= male and F = female) Date of birth (YYYY-MM-DD) Yearly salary in dollars

Department Table
The department table contains the following information about each department in the fictitious Spiff Manufacturing Company: What the departments are Who manages the departments The hierarchic relationship among the departments

Content

Co l 1 2 3 4

Column Name And Data Type DEPTNO CHAR(3) DEPTNAME VARCHAR(36) MGRNUMBER CHAR(6) ADMDEPT CHAR(3)

Nulls Allowe d No No No No

Description A unique set of three alphanumeric characters to identify the department A name describing the general activities of the department Employee number (EMPNO) of the department manager DEPTNO of the department to which the subject department reports to administratively. This column is blank if the department does not report to another

department

Project Table
The project table contains information about each project that the company is working on. Content

Co l 1 2 3 4 5

Column Name And Data Type PROJNO CHAR(6) PROJNAME VARCHAR(24) DEPTNO CHAR(3) RESPEMP CHAR(6) PRSTAFF DECIMAL(5,2)

Nulls Allowe d No No No No Yes

Description Project ID (a unique designator of six alphanumeric characters) Project name ID of the department responsible for the project ID of the employee responsible for the project Estimated mean project staffing (mean number of persons) needed between STARTDATE and ENDDATE to achieve the whole project, including and subprojects Estimated project start date (YYYY-MM-DD) Estimated project end date (TTTT-MM-DD) ID of any major project of which the subject project may be a part

6 7 8

STARTDATE DATE ENDDATE DATE MAJPROJ CHAR(8)

Yes Yes No

Project-Activity Table
The project-activity table contains the information about activities as they pertain to each project Content

Co l 1 2 3

Column Name And Data Type PROJNO CHAR(6) ACTNO SMALLINT ACSTAFF DECIMAL(5,2)

Nulls Allowe d No No Yes

Description Project ID (an alphanumeric designator of the project) Activity ID (an alphanumeric designator of the activity) Estimated mean activity staffing (mean number of persons) needed between STARTDATE and ENDDATE to achieve the ACTNO (type of activity) for the subject project. Estimated activity start date (YYYY-MM-DD) Estimated activity completion date (YYYY-MM-DD)

4 5

STARTDATE DATE ENDDATE DATE

Yes Yes

Employee-to-Project-Activity Table
The employee-to-project-activity table provides information about the projects and activities to which employees are assigned. Content

Co l 1 2 3 4

Column Name And Data Type EMPNO CHAR(6) PROJNO CHAR(6) ACTNO SMALLINT EMPTIME DECIMAL(5,2)

Nulls Allowe d No No No No

Description Employee number (unique ID) Project number of the project to which the employee is assigned to perform all or part of the activity ID of an activity within a project to which an employee is assigned A number ranging from 0.00 to 1.00 to indicate the percentage of time an employee is to spend on the subject project from STARTDATE to ENDDATE Date the activity starts (YYYY-MM-DD) Completion date of the activity (YYYY-MM-DD)

5 6

STARTDATE DATE ENDDATE DATE

No No

How to Prepare SQL Input File and Run SQL Program You need to write SQL statements to run query. The following are three methods for preparing SQL statements input files, Method 1: SQL statements can be written at SQL prompt while you are logged into Oracle. One of the disadvantages of this method is that it may be difficult to edit input statements. SQL > SQL QUERY STATEMENT_1;

OUTPUT SQL > SQL QUERY STATEMENT_2; OUTPUT SQL > ------------SQL > SQL QUERY STATEMENT_n; OUTPUT Method 2: Type SQL statements into an editor such as Notepad initially and then use the Copy and Paste functions to paste SQL statements into Oracle. This is useful when you need to prepare a substantial number of SQL statements and editing will be needed. SQL > SQL QUERY STATEMENT_1; SQL QUERY STATEMENT_2; SQL QUERY STATEMENT_3; ------------SQL QUERY STATEMENT_n; OUTPUTS Method 3: Type SQL statements into a text file with sql extension. For example, you have created a file named lab1 with an sql extension such as lab1.sql. Next, you type SQL statements into the file and save the file. After doing this you can execute the file at SQL prompt by using the start or @ command. SQL > start lab1.sql OUTPUTS OR SQL > @ lab1.sql OUTPUTS

How to Print SQL Query Outputs Method 1: This alternative is to use Select, Copy, and Paste functions. Method 2: This alternative is to use Spool function. Before running SQL programs, create a spool file (for example, lab1out) by going to the file menu and selecting the spool option. Then click on spool file. A new window will appear to allow you to create a file in a specified location. Choose the floppy drive, d:\drive, or your home folder, type in a file name (for example, lab1out) and click save. Once the output spool file is created, outputs will be saved in the file. In other words, the output of all the queries will be collected in a file named lab1out. After you have finished running SQL programs, return to the file menu and select spool option. Then click on spool off. To print the outputs you simply open the output file using Notepad. Now you are ready to print the outputs. How to Create Tables If tables are not available for some reasons, you may obtain a disk from the instructor to create tables. The procedure is as follows, At SQL> prompt, type the following, SQL>@a:\runscripts.sql Then press Enter key, all six tables for the sample company, Spiffy Manufacturing Company, will be created.
Revised 09/12

You might also like