Laboratory 5 Getting Started With Oracle SQL PLUS™: Helpful Tips: 1. Create A Table
Laboratory 5 Getting Started With Oracle SQL PLUS™: Helpful Tips: 1. Create A Table
Laboratory 5 Getting Started With Oracle SQL PLUS™: Helpful Tips: 1. Create A Table
References
Lecture Notes: Topic 6 - Elmasri and Navathe, 2017: Chapter 6
In this laboratory session you will begin using Oracle SQL to create tables and manipulate data.
In this session, you can use a convenient online tool to get started – Oracle Live SQL:
https://livesql.oracle.com/
Here below is a quick video (7 mins) link to teach you how to use Oracle Live SQL (please do
have a look at it before you start to use it):
https://www.youtube.com/watch?v=4oxsxJQQC-s
Since next week, you will be given an Oracle APEX account and you also can use APEX to work
on your SQL labs or assignments.
Helpful Tips:
1. Create a table:
2. Insert a record:
1
5. Change attribute type in a table:
UPDATE tableName
SET attributeName = newValue
WHERE attributeName = searchValue;
8. Drop a table:
SHOW RECYCLEBIN;
PURGE RECYCLEBIN;
Discussion Questions
1. What is SQL?
SQL stands for Structured Query Language. It is the formal standard language for defining
and manipulating relational databases.
2. What is Oracle?
2
Exercise 1 – Creating Tables, Adding Constraints and Inserting Data
(Note: Please make sure to clear the SQL Worksheet before you type and run the new SQL
statement(s))
1. At the SQL Worksheet type the following statement and write down your observations.
(Note: your observation should not be a number, if you get a number can you tell what it is?)
SELECT *
FROM TAB;
TAB is a pre-defined table that stores, amongst other things, information regarding the tables
in your database.
3. Clear your SQL Worksheet and type the following statement and write down your
observations.
SELECT *
FROM TAB;
4. Clear your SQL Worksheet and type the following statement and write down your
observations.
DESCRIBE Venues;
3
5. Clear your SQL Worksheet and type the following SQL statement.
Once you have successfully added the above row (Oracle will tell you when you are
successful – "1 row(s) inserted"), clear your SQL Worksheet and try inserting the next
record.
6. Note that if you are entering values for all the attributes in a table, as in 5 above, you do not
need to include the attribute names. Clear your SQL Worksheet and type the following SQL
statement.
7. If you are only entering partial information you MUST specify the attributes and ensure that
all NOT NULL fields have a value. Clear your SQL Worksheet and type the following SQL
statement.
Any problems?
4
8. Please create a table call Event in the database, table Event includes the following
attributes, and the primary key is eventId, foreign key is venueId, please define these
attributes appropriately.
9. How do you ensure cateringRequired in the table above is only given the values 'y' or
'n'?
cateringRequired CHAR(1)
CHECK (cateringRequired IN ('N', 'n', 'Y', 'y'))
10. What is the SQL statement to display all the records in the Venue table? Try it and see.
12. Clear your SQL Worksheet and type the following SQL statement.
5
('E00002', 'Little Athletic''s Trivia Night', 'Fundraiser for
the local little athletics club', 250, 'n', 'V00009');
1. Please drop attribute venueManager from table Venues without recreating the table.
DESCRIBE Venues;
4. Type the following statements and write down your observations. Take particular note of the
order in which the attributes are listed. What impact will this have on future insert
statements?
DESCRIBE Venues;
DESCRIBE Venues;
DESCRIBE Venues;
6
8. Write the SQL statement to update the street address of the venues with id 'V00001' to '12
Lyndhurst St'.
UPDATE Venue
SET streetAddress = '12 Lyndhurst St'
WHERE venueID = 'V00001';
9. Write the SQL statement to delete the venue with venueId 'V00002' from the Venues
table.
10. Write the SQL statement to delete the venue with venueId 'V00001' from the Venues
table.
What happens?
2. Correct the code to drop the table Venues that has a referential integrity constraint with
another table?
To drop a table that has a referential integrity constraint with another table you can issue
the following command:
7
4. When you issue the drop table command the table is placed in the recycle bin, thereby
allowing you to retrieve it if necessary. If you want to retrieve the table, what command you
need to type?
If you issue the command to see the tables in your database, you will see that the Venues
table has been reinstated.
5. When you selected the tables in the database after dropping the Venues table you will have
noticed that the representation of the Venues table does not make it easy to identify. What
command you need to type to identify Venues table in recycle bin?
show recyclebin;
Should you want to retrieve tables from the recycle bin this command will help you identify
them.
6. To delete a table from the recycle bin you need to "purge" it. Please type code to delete the
table Venues from recycle bin. After that, at the SQL prompt type the following statements
and write down your observations.
7. Please type the code to delete all the tables in your recycle bin.
PURGE recyclebin;
8
A word on style…
The commands in SQL*PLUS are not case sensitive. The mixed use of upper- and lower-case in
this lab is for readability only. HOWEVER, it is suggested you follow a similar format when
writing your SQL statements.
For more practice try the following from your text book (Elmasri and Navathe, 2014):