Database Programming With SQL 15-2: DML Operations and Views Practice Activities

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Database Programming with SQL

15-2: DML Operations and Views


Practice Activities
Objectives
• Write and execute a query that performs DML operations on a simple view
• Name the conditions that restrict modifying a view using DML operations
• Write and execute a query using the WITH CHECK OPTION clause
• Explain the use of WITH CHECK OPTION as it applies to integrity constraints and data
validation
• Apply the WITH READ ONLY option to a view to restrict DML operations

Vocabulary
Identify the vocabulary word for each definition below.

A pseudocolumn which assigns a sequential value starting with 1


to each of the rows returned from the subquery
Specifies that INSERTS and UPDATES performed through the
view can’t create rows which the view cannot select
Ensures that no DML operations can be performed on this view

Try It / Solve It

Use the DESCRIBE statement to verify that you have tables named copy_d_songs, copy_d_events,
copy_d_cds, and copy_d_clients in your schema. If you don't, write a query to create a copy of each.

1. Query the data dictionary USER_UPDATABLE_COLUMNS to make sure the columns in the base
tables will allow UPDATE, INSERT, or DELETE. Use a SELECT statement or the Browse Data
Dictionary feature in HTML DB. All table names in the data dictionary are stored in uppercase.

2. Use the CREATE or REPLACE option to create a view of all the columns in the copy_d_songs
table called view_copy_d_songs.

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
3. Use view_copy_d_songs to INSERT the following data into the underlying copy_d_songs table.
Execute a SELECT * from copy_d_songs to verify your DML command. See the graphic.

ID TITLE DURATION ARTIST TYPE_CODE


88 Mello Jello 2 The What 4

4. Create a view based on the DJs on Demand COPY_D_CDS table. Name the view
read_copy_d_cds. Select all columns to be included in the view. Add a WHERE clause to restrict
the year to 2000. Add the WITH READ ONLY option.

5. Using the read_copy_d_cds view, execute a DELETE FROM read_copy_d_cds WHERE


cd_number = 90;

6. Use REPLACE to modify read_copy_d_cds. Replace the READ ONLY option with WITH CHECK
OPTION CONSTRAINT ck_read_copy_d_cds. Execute a SELECT * statement to verify that the
view exists.

7. Use the read_copy_d_cds view to delete any CD of year 2000 from the underlying copy_d_cds.

8. Use the read_copy_d_cds view to delete cd_number 90 from the underlying copy_d_cds table.

9. Use the read_copy_d_cds view to delete year 2001 records.

10. Execute a SELECT * statement for the base table copy_d_cds. What rows were deleted?

11. What are the restrictions on modifying data through a view?

12. What is Moore’s Law? Do you consider that it will continue to apply indefinitely? Support your
opinion with research from the internet.

13. What is the “singularity” in terms of computing?

Copyright © 2020, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.

You might also like