Uploaded by Carlo Medina

F3-FORMATIVE Medina, Don Carlo Miguel Neyra

advertisement
COLLEGE OF COMPUTER STUDIES
CCS0021L
(INFORMATION MANAGEMENT)
[F3-FORMATIVE]
Formative Assessment 3
EXERCISE
5
INTRODUCTION TO SQL
Student Name / Group
Name:
Members (if Group):
Name
Medina, Don Carlo
Miguel Neyra
Section:
BFM21
Professor:
Mam Beth Sta. Ana
I.
Role
PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE
a. Apply knowledge through the use of current techniques and tools necessary for the IT profession. [PO: I]
II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE
• Create SQL statements that retrieve information requirements of the organization needed for reports generation.
[CLO: 4]
CCS0021L-Information Management
Page 2 of 51
III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE
At the end of this exercise, students must be able to:
•
•
Understand SQL Developer to execute SQL Statement
Explore the SQL Environment using SQL
IV. BACKGROUND INFORMATION
SQL ENVIRONMENT
Catalog
•
A set of schemas that constitute the description of a database
Schema
•
The structure that contains descriptions of objects created by a user (base tables, views,
constraints)
Data Definition Language (DDL)
•
Commands that define a database, including creating, altering, and dropping tables and
establishing constraints
Data Manipulation Language (DML)
•
Commands that maintain and query a database
Data Control Language (DCL)
•
Commands that control a database, including administering privileges and committing data
COMMANDS
SQL LANGUAGE
SELECT
DATA MANIPULATION LANGUAGE (DML)
INSERT
UPDATE
DELETE
MERGE
CCS0021L-Information Management
Page 3 of 51
CREATE
DATA DEFIINITION LANGUAGE (DDL)
ALTER
DROP
RENAME
TRUNCATE
COMMENT
GRANT
DATA CONTROL LANGUAGE (DCL)
REVOKE
COMMIT
TRANSACTION CONTROL
ROLLBACK
SAVEPOINT
SQL DATA TYPES
CCS0021L-Information Management
Page 4 of 51
V. LABORATORY ACTIVITY
How to Create an Autonomous Database
Pre-requisite: You should have completed the sign-up process and can login to your Oracle
cloud Account.
In the main interface of the Oracle Cloud account, click on the hamburger icon on the upper left
corner of the site. See Figure 18
CCS0021L-Information Management
Page 5 of 51
Figure 18
Then click on Oracle Database, and click Autonomous Database. See Figure 19
Figure 19
CCS0021L-Information Management
Page 6 of 51
3. Then click on Create
Autonomous Database.
See Figure 20.
Figure 20
4. Then set the following settings (Figure 21)
Compartment Name: Don’t change default settings here
Display Name: Db1LastNameFirstName or you can name any name you like
Database Name: Db1LastNameFirstName or you can name any name you like
Choose a workload type: Transaction Processing
Choose a deployment type: Shared Infrastructure
CCS0021L-Information Management
Page 7 of 51
Figure 21
5. Scroll Down. Then select the settings seen in Figure 22. Then on the Create administrator
credentials part, write a password and confirm the password. Please take note of the passwords
you are doing.
CCS0021L-Information Management
Page 8 of 51
Figure 22
6. Then scroll down. Choose the settings found in Figure 23. Then click Create Autonomous
Database.
CCS0021L-Information Management
Page 9 of 51
Figure 23
7. You will be taken to this site. For now the status is Provisioning. Give it time to set up and
load until the status becomes ‘Available’ or you can refresh the page. See Figure 24 and
25.
CCS0021L-Information Management
Figure 24
Page 10 of 51
Figure 25
CCS0021L-Information Management
Page 11 of 51
How to Access Apex and Create a Database User and Workspace
Pre requisite: You can access your Oracle Cloud account, and you have create an Autonomous
Database (Please refer to the previous page)
1. On your Autonomous Database Details, click on the Tools tab
2. Then Click on Open Apex.
3. Then login to Administration Services by writing the password (this is the password you have
chosen during creation of the Autonomous Database, Refer to figure 22). Then click on Sign In
to Administration.
CCS0021L-Information Management
Page 12 of 51
4. Then Click on Create Workspace (If this is your first time).
5. Then create a Database User that will use the database. Write the password and workspace
name. Please take note. Usually the Database User and the WorkSpace Name are the the same.
Then click Create Workspace.
CCS0021L-Information Management
Page 13 of 51
6. Then it will take you to this site. To use the newly created database user, sign out of the
administrator account by clicking the AD on the upper right corner. Then click Sign out.
7. Then click Return to Sign In page.
8. Then write the newly created workspace, username and password. Then click sign in.
CCS0021L-Information Management
Page 14 of 51
8. Now you have successfully accessed the APEX, created a database user and created a
workspace.
CCS0021L-Information Management
Page 15 of 51
How to populate the workspace using the newly created database user
Pre-requisite: You have successfully created a new database user and workspace
1. After logging in to the account of the database user. Click on the SQL Workshop down arrow
2. Click on SQL Scripts
3. Then click Upload
4. Click on Choose File and Find the hrcreate.txt file provided by your teacher. The Script name
is optional. Then click upload.
CCS0021L-Information Management
Page 16 of 51
5. Then click on the Play button.
6. Then click run now
7. Then you should be getting this screen:
CCS0021L-Information Management
Page 17 of 51
Male sure it shows 25 statements processed, 26 Successful and 0 with Errors.
8. Click the SQL Workshop down arrow and choose Object Browser to see the tables created.
9. You should be seeing this below. In the object browser you will see different tables. They
are Countries, Departments, Employees, Jobs, Job_history, Locations, and Regions.
CCS0021L-Information Management
Page 18 of 51
10. Repeat Steps 1-3 of ‘How to populate the workspace using the newly created database user’.
Then upload the file hrpopulate.txt provided by your teacher. Click upload.
11. Then make sure you click the Play button of the hrpopulate.txt.
12. Then Click run now
CCS0021L-Information Management
Page 19 of 51
13. Make sure that these are the statements processed
14. Then go back to Object browser to see the result.
15. Open the departments table by clicking on it.
CCS0021L-Information Management
Page 20 of 51
16. Click on the Data tab
17. And you will see that the departments table has data on it because of hrpopulate script.
CCS0021L-Information Management
Page 21 of 51
QUESTION AND ANSWER
1. What is difference between SQL Developer and SQL *plus?
SQL*plus is a command line tool, SQL Developer is a GUI interface to your DB. You can call SQL*PLUS from
command line and easily execute scripts so it's simple to automate tasks. SQL Developer will display db content in a
nice layout, allows you to edit data etc.
SQL Plus is a command-line interface (CLI) tool that allows users to enter SQL commands and view the results. It is
typically used by developers and database administrators to perform tasks such as creating and modifying database
objects, running queries, and managing data. It is included as part of the Oracle Database installation and does not
require a separate download.
SQL Developer, on the other hand, is a graphical user interface (GUI) tool that provides a more user-friendly
environment for working with an Oracle database. It allows users to perform many of the same tasks as SQL Plus,
but with a more intuitive interface. SQL Developer also provides additional features such as a SQL editor with syntax
highlighting and code completion, a data grid for viewing query results, and support for working with multiple
databases. It is a separate download from the Oracle website and it's free.
In summary, SQL Plus is a command-line tool for developers and DBAs to perform tasks with SQL command, SQL
Developer is a GUI based tool for developers, DBAs and other users with more functionalities and user-friendly
interface.
I.
REFERENCES
•
•
Hoffer, Jeff (2016). Modern Database Management 12th edition. Pearson Education Limited
Young, M. (2010). Oracle Data Modeling and Relational Database Design, Vol. 1 Student Guide, Oracle.
CCS0021L-Information Management
Page 22 of 51
EXERCISE
6
DATA DEFINITION LANGUAGE
Student Name / Group
Name:
Members (if Group):
Name
Medina, Don Carlo
Miguel Neyra
Section:
BFM21
Professor:
Mam Beth Sta. Ana
I.
Role
PROGRAM OUTCOME/S (PO) ADDRESSED BY THE LABORATORY EXERCISE
b. Apply knowledge through the use of current techniques and tools necessary for the IT profession. [PO: I]
II. COURSE LEARNING OUTCOME/S (CLO) ADDRESSED BY THE LABORATORY EXERCISE
• Create SQL statements that retrieve information requirements of the organization needed for reports generation.
[CLO: 4]
CCS0021L-Information Management
Page 23 of 51
III. INTENDED LEARNING OUTCOME/S (ILO) OF THE LABORATORY EXERCISE
At the end of this exercise, students must be able to:
•
Use SQL commands to manage tables
•
Establish referential integrity using
IV. BACKGROUND INFORMATION
•
This statement is one of the DDL statements that are a subset of the SQL statements used to create, modify, or
remove Oracle database structures.
Syntax:
CREATE TABLE [schema.]table
(column datatype [DEFAULT expr] [, …]);
Constraints
The Oracle server uses constraints to prevent invalid data entry into tables.
You can use constraints to do the following:
• Enforce rules on the data in a table whenever a row is inserted, updated, or deleted from that table. The constraint
must be satisfied for the operation to succeed.
• Prevent the deletion of a table if there are dependencies from other tables.
• Provide rules for Oracle tools, such as Oracle Developer.
Data Integrity Constraints
Constraint
Description
NOT NULL
Specifies that the column cannot contain a null value
UNIQUE
Specifies a column or combination of columns whose values
must be unique for all rows in the table
PRIMARY KEY
Uniquely identifies each row of the table
FOREIGN KEY
Establishes and enforces a referential integrity between the
column and a column of the referenced table such that values
in one table match values in another table.
Defining Constraints
Syntax:
CHECKCREATE TABLE [sc h Se mpae. c] t ai fbil ee s a condition that must be true
(column datatype [DEFAULT expr]
[column_constraint],
…
[table_constraint] [, …]);
•
Column-level constraint syntax:
CCS0021L-Information Management
Page 24 of 51
Syntax:
column [CONSTRAINT constraint_name] constraint_type,
•
Table-level constraint syntax:
Syntax:
column, …
[CONSTRAINT constraint_name] constraint_type
(column, …),
Creating a Table Using a Subquery
• Match the number of specified columns to the number of subquery columns.
• Define columns with column names and default values.
Syntax:
CREATE TABLE table
[(column, column…)]
AS subquery;
Read-Only Tables
You can use the ALTER TABLE syntax to:
• Put a table into read-only mode, which prevents DDL or DML changes during table maintenance
• Put the table back into read/write mode
Syntax:
ALTER TABLE table READ ONLY;
ALTER TABLE table READ WRITE;
Dropping a Table
• Moves a table to the recycle bin
• Removes the table and all its data entirely if the PURGE clause is specified
Syntax:
DROP TABLE table [PURGE];
Inserting Data into the Table
•
With this syntax, only one row is inserted at a time
Syntax:
INSERT INTO table [(column [, column…])]
VALUES (value [, value…]);
•
Copying rows from another table
Syntax:
INSERT INTO table [(column [, column…])]
subquery;
ALTER TABLE Statement
Syntax:
ALTER TABLE table
ADD(column datatype [DEFAULT expr]
CCS0021L-Information Management
Page 25 of 51
[, column datatype]…);
ALTER TABLE table
MODIFY (column datatype [DEFAULT expr]
[, column datatype]…);
ALTER TABLE table
DROP (column);
Adding a Constraint
Syntax:
ALTER TABLE table
ADD(CONSTRAINT constraint_name] type column_name;
Dropping a Constraint
Syntax:
ALTER TABLE table
DROP PRIMARY KEY | UNIQUE (column) |
CONSTRAINT constraint [CASCADE];
FLASHBACK TABLE Statement
Syntax:
FLASHBACK TABLE [schema.]table [, [schema.]table]…
TO {TIMESTAMP | SCN} expr;
CCS0021L-Information Management
Page 26 of 51
V. GRADING SYSTEM / RUBRIC
Criteria
Creation of Tables (1-10
Changes made on the Tables
Total
CCS0021L-Information Management
Descriptions
Points
All the tables in the ERD are properly made
and complete
The use of correct Data Definition
Language to change the characteristics of
the table are correct
100%
50
50
Page 27 of 51
VI. LABORATORY ACTIVITY
DO THE FOLLOWING:
How to connect SQL Developer to Oracle Cloud Account
Pre-requisite:
•
You have the application SQL developer application.
(To download please click on this site:
https://www.oracle.com/tools/downloads/sqldev-downloads.html
Once downloaded, no need to install, find the sqldeveloper.exe and run it.)
•
You have an Oracle cloud account, you have a database user and workspace set up and you can
access the administration account of your Cloud account. If you do not have these, please do the
required steps before doing this.
1. The first thing to do is to get your Database Wallet. You will be needing this later in SQL
developer. Login to your oracle cloud account and go to your autonomous database account.
Click on the display name of your Autonomous Database.
2. Click on the DB Connection
CCS0021L-Information Management
Page 28 of 51
3. Choose Instance Wallet and click Download Wallet.
4. Write a password and confirm the password for this wallet. Make sure you remember the
password because you will be needing it later in SQL developer. Then click Download Wallet.
Make sure you know where you saved the wallet you have downloaded.
5. Then run SQL developer.
This is the loading interface of Oracle SQL
Developer.
CCS0021L-Information Management
Page 29 of 51
This is the interface of Oracle SQL developer.
6. Click the New Connection Icon (the green Plus icon) on the Connections pane.
CCS0021L-Information Management
Page 30 of 51
7. Write in the Name the name of the User or any name (this is just the label of your connection)
, in this case its UserJohnSantos. Write the username and password of the database user. In this
case its UserJohnSantos and its password
8. On the Connection Type choose: Cloud Wallet
CCS0021L-Information Management
Page 31 of 51
9. On the configuration file, click on Browse…Look for the cloud wallet you have downloaded
earlier.
CCS0021L-Information Management
Page 32 of 51
10. Once the wallet is chosen, click on Test button
11. The status should be Success
CCS0021L-Information Management
Page 33 of 51
12. Then Click Save
13. You will be seeing it on the Connection Name part
14. Then click Connect.
CCS0021L-Information Management
Page 34 of 51
15. Its going to ask you to input your password again. Type it in and click Ok.
16. You will see in the Connections pane a plug icon, meaning your SQL developer has
successfully connected to your Oracle Cloud account
17. We can verify it by clicking the + icon
18. Click on the + icon of the Tables (Filtered)
19. You will see the same tables you had in the Oracle Cloud.
CCS0021L-Information Management
Page 35 of 51
Given the Entity Relationship Diagram below both Logical and Relational Diagram:
CCS0021L-Information Management
Page 36 of 51
Create the tables given in the ERD using Oracle Cloud Account in your SQL developer. The attributes and the
relationships are found on the diagrams
For each number, copy the source code and paste it here together with the screenshot of the what the table looks
like by its Columns
1. Source code and screenshot of the table for creating the Customer table.
CCS0021L-Information Management
Page 37 of 51
2. Source code and screenshot of the table for creating the Item table.
3. Source code and screenshot of the table for creating the ItemProduct table.
CCS0021L-Information Management
Page 38 of 51
4. Source code and screenshot of the table for creating the Orders table.
5. Source code and screenshot of the table for creating the Product table.
CCS0021L-Information Management
Page 39 of 51
6. Source code and screenshot of the table for creating the Requests table.
CCS0021L-Information Management
Page 40 of 51
7. Source code and screenshot of the table for creating the Shipment table.
8. Source code and screenshot of the table for creating the ShipmentItem table.
CCS0021L-Information Management
Page 41 of 51
9. Source code and screenshot of the table for creating the Supplier table.
CCS0021L-Information Management
Page 42 of 51
10. Source code and screenshot of the table for creating the SupplierItem table.
CCS0021L-Information Management
Page 43 of 51
11. Write a DDL code the add new columns on the Customer table. The new column’s name are Address, Postal
Code, Province, Zip Code. The new columns are all data type Vachar2(100). Copy and paste the source
code and screenshot of the updated table below:
CCS0021L-Information Management
Page 44 of 51
12. Change the Quantity attribute to QTY in the item Table. Copy and paste the source code and screenshot of
the updated table below:
13. Rename the following tables:
ItemProduct to DetailsOfProduct
ShipmentItem to ShipmentDetails
SupplierItem to SuppliersInvoice
Copy and paste the source code and screenshot of the updated table below:
CCS0021L-Information Management
Page 45 of 51
ShipmentDetails
SuppliersInvoice
DetailsOfProduct
14. Increase the number of characters on the attribute ProductCategory in the Product table. Increase it from 500
to 600. Copy and paste the source code and screenshot of the updated table below:
CCS0021L-Information Management
Page 46 of 51
15. Type in Commit on the worksheet, to save the changes made. Copy and paste the code below:
16. Create a new table. Name the table TempTable. Create two attributes of your own, one of the attributes is an
identifier. Copy and paste the source code and screenshot of the updated table below:
CCS0021L-Information Management
Page 47 of 51
17. Delete the table TempTable. Copy the code you have used and take a screenshot of the your Recycle bin
and paste it here:
18. Restore the table TempTable back to the Tables Schema. Copy and paste the source code and screenshot of
the updated table below:
CCS0021L-Information Management
Page 48 of 51
19. Make the table TempTable to an uneditable table. Copy and paste the source code and screenshot of the
updated table below:
20. Create a comment on the column Customerid of the Customer table. Copy and paste the code below:
CCS0021L-Information Management
Page 49 of 51
I.
QUESTION AND ANSWER
1. What is the purpose of Data Definition Language in SQL?
Data Definition Language (DDL) is used to create and modify the structure of objects in a database using predefined
commands and a specific syntax. These database objects include tables, sequences, locations, aliases, schemas,
and indexes.
Data definition language (DDL) refers to the set of SQL commands that can create and manipulate the structures of a
database. DDL statements are used to create, change, and remove objects including indexes, triggers, tables, and
views.
II. REFERENCES
•
Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2007). Modern Database Management 8th Edition. New
Jersey: Pearson Prentice Hall
CCS0021L-Information Management
Page 50 of 51
CCS0021L-Information Management
Page 51 of 51
Download
Study collections