You are on page 1of 5

CMPSC245 Assignment 2

Students will learn how to use Oracle APEX and create tables using APEX.

Task1: Login to APEX workspace


1. Login to APEX: https://iacademy3.oracle.com/
2. Here is the information that you will need to connect:
 Workspace: US_A926_PLSQL_S02
 Username: ICC Student ID
 Password: Pa$$w0rd
Note: Do not change the password so that you keep Pa$$w0rd

Task 2: SQL commands Window


 Click ‘SQL Workshop’ drop down arrow -> click SQL Commands. You can see the screenshot below.
 Type SELECT * FROM books; on the statement window. Then Click Run button.
 To save this query, click Save button and then save this query as “SelectAllBooks“.
 If you want to run this saved query, click Saved SQL tab and double-click “SelectAllBooks”.

1
4

2 5
3
2

1. Schema: display the schemas to which you have been granted access.

2. Statement window: type SQL or PL/SQL commands in this window.

3. Run button: execute the SQL or PL/SQL statement.

4. Save button: You run your SQL or PL/SQL statement or save it for future use. To limit the
number of times you enter a common SQL or PL/SQL statement, save the statement by clicking
the Save button.
5. If you want to run the saved SQL, click Saved SQL tab on the bottom, double-click one of saved
SQLs you want to run like:

Task 3: Creating scripts


SQL commands menu allows you to type only one statement. If you want to run multiple statements,
create a script file and then run it.

Click ‘SQL Workshop’ drop down arrow -> select SQL Scripts -> Click the ‘Create’ button.
1. Move to Script Name textbook and type your script a name like “Create copy tables”.
2. Enter SQL statements below.
3. Click “Create” button
4. Click “Run” button
5. Click “Run Now” button on the bottom.

1
2

3 4
2
2 2
2
Click SQL Workshop drop down arrow -> select Object browser -> you can see two tables added.
Task 4: Creating Tables
Click “SQL Workshop” drop down arrow -> click “SQL Commands”.
Write SQL statements for creating table with the following specification:
1. Create a table called “yourfirstname_Advisors” with the following properties:
• Create a numeric column called “advisorID” which is a primary key.
• Create a character column called “advisorMajor” with a default value ‘CS’.
• Add a varchar2 column named advisorName with the length 30.

CREATE TABLE James_Advisors (


advisorID NUMBER(4,0) PRIMARY KEY,
advisorName VARCHAR2(30),
advisorMajor VARCHAR2(20) DEFAULT ‘CS’);

2. Create another table called “yourfirstname_Students” with the following properties:


• There is a one-to-many relationship between Advisor and Student tables. So, you need to
consider the referential Integrity between them.
• Create a numeric column called “studentID” which is a primary key.
• Create a numeric column called “advisorID” which is a foreign key with table
yourfirstname_Advisors.

CREATE TABLE James_Students (


studentID NUMBER(4,0) PRIMARY KEY,
studentName VARCHAR2(30),
advisorID NUMBER(4,0) REFERENCES James_Advisors(advisorID)) ;
3. Write SQL statements to insert a sample record to each table.
INSERT INTO James_Advisors (advisorID, advisorName, advisorMajor) VALUES (10, 'James Shult',
‘EE’);
INSERT INTO James_Students (studentID, studentName, advisorID) VALUES (20, 'Mark Nelson', 10);

4. Create a SQL script that displays all advisors and students.


SELECT * from James_Advisors;
SELECT * from James_Students;

Remember: Select statement does not have any issue but Update statements (update and delete
statements) maybe not be worked on Apex.

Your Turn:
Please open the following link: https://www.docdroid.net/uaTFHrh/oracle-11g-sql-by-joan-
casteel.pdf#page=82 and read chapter 3: Table Creation and Management and then answer the
following:
 (0.7 point each) Multiple Choice: 20 questions
 Writing SQL statements:
 (3 pts each) Page 94, Hand-on Assignments
Question 1 through 10
 (3 pts each) Advanced challenge: skip the first question, answer only second and third questions.
Please test all SQL statements on Apex.
Remember: Whenever you create a table, please begin prefix with your first name followed by the table
name. e.g., if “James” wants to create Employee table, his table name should be James_Employee.
Answers
1. C.
2. C.
3. A.
4. D.
5. D.
6. D.
7. B.
8. D.
9. B.
10. A.
11. D.
12. A.
13. A.
14. B.
15. D.
16. D.
17. B.
18. D.
19. C.
20. B.
Page 94 Hand-on Assignment
1. CREATE TABLE CATEGORY (Catcode Varchar2 (2),
CatDesc Varchar2(10));
2. Create TABLE EMPLOYEES (Emp# NUMBER (5),
Lastname Varchar2(15), Firstname Varchar2(15),
Job_class Varchar (4));
3. ALTER TABLE EMPOYEES ADD (EmpDate DATE DEFAULT SYSDATE, Endate DATE);
4. ALTER TABLE EMPLOYEES MODIFY ( Job_class Varchar (10));
5. ALTER TABLE EMPLOYRSS
6. RENAME EMPLOYEES TO JL_EMPS;
7. CREATE TABLE BOOK_PRICING (ID Number (5), Cost varchar2(20), Retail varchar2(10),
Category varchar (4));
8. ALTER TABLE BOOK_PRICING SET UNUSED (Category);
9. TRUNCATE TABLE BOOKING_PRICING;
10. DROP TABLE BOOK_PRICING PURGE;
DROP TABLE JL_EMPS;
Advance Challenge
2. CREATE TABLE COMMRATE (Comm_ID numeric (10), Comm_rank varchar (15), Rate numeric
(10,2));
3.CREATE TABLE BENEFITS (Ben_ID numeric(10), Ben_Plan char(1), Ben_Provider numeric (3),
Active char(1));
Turn-in Instructions
 Write all your answers on the WORD document.
 Save all results as “Assignment2_CreatingTables_yourfirstname.docx” and submit it to the E-
Portfolio/File Exchange.

You might also like