instructor guide database programming - section 12 -...

60
Database Programming - Section 12 Instructor Guide

Upload: vanminh

Post on 25-Mar-2018

234 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Database Programming - Section 12 Instructor Guide

Page 2: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students
Page 3: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page i

Table of Contents

Database Programming - Section 12..............................................................................................................1 Lesson 1 - Practice Exercises and Quiz .........................................................................................................1 What Will I Learn? ........................................................................................................................................2 Why Learn It?................................................................................................................................................3 Tell Me / Show Me........................................................................................................................................4 Try It / Solve It ..............................................................................................................................................5 Lesson 2 - Looking for a Job .........................................................................................................................6 What Will I Learn? ........................................................................................................................................8 Why Learn It?................................................................................................................................................9 Tell Me / Show Me........................................................................................................................................10 Try It / Solve It ..............................................................................................................................................11 Lesson 3 - Sequences.....................................................................................................................................13 What Will I Learn? ........................................................................................................................................15 Why Learn It?................................................................................................................................................16 Tell Me / Show Me........................................................................................................................................17 Try It / Solve It ..............................................................................................................................................27 Lesson 4 - Indexes and Synonyms.................................................................................................................29 What Will I Learn? ........................................................................................................................................30 Why Learn It?................................................................................................................................................31 Tell Me / Show Me........................................................................................................................................32 Try It / Solve It ..............................................................................................................................................44 Lesson 5 - Practice Exercises and Review.....................................................................................................46 What Will I Learn? ........................................................................................................................................47 Why Learn It?................................................................................................................................................48 Tell Me / Show Me........................................................................................................................................49 Try It / Solve It ..............................................................................................................................................50

Page 4: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students
Page 5: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 1

Lesson 1 - Practice Exercises and Quiz

Lesson 1 - Practice Exercises and Quiz

Lesson Preparation

None. What to Watch For

None. Connections

None.

Page 6: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 2

What Will I Learn?

What Will I Learn?

Page 7: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 3

Why Learn It?

Why Learn It?

Page 8: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 4

Tell Me / Show Me

Tell Me / Show Me

Page 9: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 5

Try It / Solve It

Try It / Solve It

Try It / Solve It

Complete and review the practice exercises. Assign SQL Quiz. A passing score is 7 out of 10. Assessment: You may want to encourage students to retake the quiz until they achieve a passing score. Or you may prefer to allow only one attempt at the quiz. Allow 20 minutes for the quiz and 10 minutes for assessment/discussion afterward. Have students work in pairs to review what they missed on the quiz. Based on the types of questions they missed, have each pair of students choose one question they missed or did not understand to present to the group. Use this discussion to assess student understanding.

Page 10: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 6

Lesson 2 - Looking for a Job

Lesson 2 - Looking for a Job

Lesson Preparation

Use the Career Exploration Worksheet that students completed in Section 1, Lesson 5. Students can use the worksheet to help them identify jobs that match the areas of interest previously identified. Internet access is required for this lesson. The following Internet sites are good places for students to begin looking (search-engine keywords: best colleges, trade schools): http://www.usnews.com/usnews/edu/college/rankings/rankindex_brief.php -- United States listings http://univ.cc/ -- worldwide listings http://www.scholarstuff.com/colleges/colleges.htm http://www.myfuture.com/t2_milops.html -- military careers

What to Watch For Discourage students from searching for "professional skateboarder," "rock star," and "pro soccer player" types of jobs. Help them to be realistic in their choices -- at least in their search here!

Page 11: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 7

Connections Encourage students to always be looking at current job offerings and reading about new types of jobs and jobs of the future. Ask students to bring to class articles and news stories about jobs and the job market. If your school has a career center or career counselor, ask them to speak to the class about the transition from high school to work or to college. Many students do not understand the transition process and how to begin applying for college or looking for a job.

Page 12: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 8

What Will I Learn?

What Will I Learn?

Page 13: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 9

Why Learn It?

Why Learn It?

Page 14: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 10

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Explain to students that the purpose of this activity is to begin looking at what job skills are needed in the current job market in the areas of their interest. For those students who still have another year or two before graduation, encourage them to look at the job qualifications. What additional courses in school could they take to make themselves more marketable? Let students know it's not too late to improve their math skills, take an advanced-placement course, add a foreign language, etc. before graduation. Discourage students from searching for "professional skateboarder," "rock star," and "pro soccer player" types of jobs. Help them to be realistic in their choices -- or at least in their search here!

Page 15: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 11

Try It / Solve It

Try It / Solve It

Try It / Solve It

Assist students in finding specific job openings in database-related fields and other fields of their choice. 1. Require each student to list the qualifications for one job in the area of their interest that is currently being advertised. Where is the job? What benefits does the job offer? What is the pay range? Go to the Monster Board, Dice, Hot Jobs, or specific company web sites such as Google, click on "jobs" and preview the current jobs being advertised or Costco and click on "employment opportunities." Try to find jobs in your local area. Search jobs with the keywords: "SQL" or "database," "data modeling," "DBA" or "database administrator." Discuss various types of jobs, locations, pay, etc. List the results of various jobs students found in a chart or map on the board. Which regions have more jobs? Why? How does the local job market compare with other areas in the country?

Page 16: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 12

2. Discuss with students the possibility that they may be offered a job in some location distant from their city. What factors are important in making a decision to take the job? Tell students that often to get the job they want they may have to move a long way from home. Consider cost of living and how to assess that; friends and family; activities that they can do in this location; challenges they may face in this location -- cold weather, hot weather, rural setting, urban setting. 3. Have students complete the IT Job Application. Discuss with students the importance of preparing a neat, complete, and accurate application. Suggest ways to obtain permission to use personal references. Mention the need to prepare a cover letter and/or resume that accompanies the application. Tell students to avoid negative comments on an application and to never leave a required box blank. How to write a resume and a cover letter will be covered in Section 13, Lesson 2.

Page 17: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 13

Lesson 3 - Sequences

Lesson 3 - Sequences

Lesson Preparation

For the practice exercises in this lesson, HTML DB allows the creation of sequences and the use of a pseudocolumn called NEXTVAL to retrieve the next value in a generated sequence. However, the pseudocolumn called CURRVAL is not accessible in the HTML DB environment. Once you retrieve the NEXTVAL from the sequence, you no longer have a "session" and the database no longer knows what’s in CURRVAL. If a statement attempts to retrieve CURRVAL, a report error is generated: ORA-08002: sequence SEQ_D_SONGS_SQ.CURRVAL is not yet defined in this session

What to Watch For Students may not completely understand NEXTVAL and CURRVAL. Use NEXTVAL to extract successive sequence numbers from a specified sequence. You must qualify NEXTVAL with the sequence name. sequencename.NEXTVAL creates the new sequence number and the current sequence number is placed in CURRVAL. CURRVAL is used to refer to a sequence number that the current user has just generated. NEXTVAL must be used first (filled) before CURRVAL can be referenced.

Page 18: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 14

Connections Use the following as an extension activity or as an additional assignment. Relate the concepts learned in the Sections 8-11 with the following example problem. (1) Create a table called "students." You can decide which columns belong in that table and what data types these columns require. (The students may create a table with different columns; however, the important piece that must be there is the student_id column with a numeric data type. This column length must allow the sequence to fit, e.g. a column length of 4 with a sequence that starts with 1 and goes to 10000000 will not work after student #9999 is entered.) CREATE TABLE students (student_id number (5), first_name VARCHAR2(10), last_name VARCHAR2(15), sectionnumber(4)); (2) Create a sequence called student_id_seq so that you can assign unique student_id numbers for all students that you add to your table. CREATE SEQUENCE student_id_seq INCREMENT BY 1 START WITH n MAXVALUE nnnnn NOCACHE NOCYCLE ; Ask students what it means if they specified NOCYCLE when they defined their sequence. It means numbers will not be reused. Ask why that might be important. (Perhaps the school wants to keep track of how many different students have ever attended the school. Perhaps students may leave the school, and then come back to the school, but still keep their original student id. This example is great for explaining NOCYCLE -- can you use a similar example in the lecture content?) (3) Now write the code to add students to your STUDENT table, using your sequence “database object.” INSERT INTO student (student_id, first_name, last_name, section) VALUES( class_student_id_seq.NEXTVAL, 'Joe', 'Smith', 1); INSERT INTO class(student_id, first_name, last_name, section) VALUES( class_student_id_seq.NEXTVAL, 'Fred', 'Jones', 10); Again, their code could be different depending on what columns they used to create their tables. The important part for students to include in this code is the use of NEXTVAL. You may want to reiterate the CURRVAL issue with HTML DB here.

Page 19: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 15

What Will I Learn?

What Will I Learn?

Page 20: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 16

Why Learn It?

Why Learn It?

Page 21: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 17

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Using the graphic description of the SEQUENCE syntax, explain what each term means in general terms.

Page 22: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 18

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Give an example of CYCLE such as phone numbers. If a phone number is a sequence issued by the phone company, once you change numbers, someone else can get that number.

Page 23: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 19

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Relate CACHE to computer cache used by browsers to store web pages. When visiting a website, your browser will cache or make a copy of the website for faster viewing in your next visit. In other words, you are calling up a copy from memory.

Page 24: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 20

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Relate NEXTVAL to being in a busy store and being required to "take a number." The machine generates a ticket (NEXTVAL) that the customer takes. When the clerk is ready to wait on the customer, CURRVAL is called.

Page 25: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 21

Tell Me / Show Me

Tell Me / Show Me

Page 26: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 22

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Briefly review the rules for NEXTVAL and CURRVAL. In the Application Builder final project, sequences will be automatically generated in HTML DB. Students will see them in a real application.

Page 27: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 23

Tell Me / Show Me

Tell Me / Show Me

Page 28: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 24

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Explain why CURRVAL cannot be accessed in HTML DB. Explain that COMMIT and ROLLBACK will be discussed in Section 17. Frequently used sequences should be created with caching to improve efficiency. For cached sequences, there is no way to find out what the next available sequence value will be without actually obtaining and using up that value. It is recommended that users resist finding the next sequence value. Trust the system to provide a unique value each time a sequence is used in an INSERT statement.

Page 29: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 25

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Review the examples shown with students.

Page 30: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 26

Tell Me / Show Me

Tell Me / Show Me

Page 31: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 27

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 1. CREATE TABLE seq_d_songs AS SELECT * FROM d_songs; SELECT * FROM seq_d_songs; 2. CREATE SEQUENCE seq_d_songs_seq INCREMENT BY 2 START WITH 100 MAXVALUE 1000 NOCACHE NOCYCLE;

Page 32: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 28

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 3. SELECT sequence_name, min_value, max_value, increment_by, last_number FROM user_sequences; 4. INSERT INTO seq_d_songs(id, title, duration, artist, type_code) VALUES(seq_d_songs_seq.NEXTVAL, 'Island Fever', '5 min', 'Hawaiian Islanders',12); INSERT INTO seq_d_songs(id, title, duration, artist, type_code) VALUES(seq_d_songs_seq.NEXTVAL, 'Castle of Dreams', '4 min', 'The Wanderers',77); 5. SELECT seq_d_songs_seq.CURRVAL FROM dual;

Page 33: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 29

Lesson 4 - Indexes and Synonyms

Lesson 4 - Indexes and Synonyms

Lesson Preparation

None. What to Watch For

This section has more descriptive information than previous sections. Read through it with the students.

Connections Make sure to explain that the use of indexes in databases is necessary for much larger databases than the students have used in this course. When large tables are mentioned, it refers to a lot of rows of data. All tables the students use in this course are small.

Page 34: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 30

What Will I Learn?

What Will I Learn?

Page 35: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 31

Why Learn It?

Why Learn It?

Why Learn It?

Relate creating an index to systematic ways in which other types of information are organized, such as the aisles in a grocery store, departments in a clothing store, numbered spaces in a parking garage, or the concourses at an airport. All make finding what we're looking for much faster and easier.

Page 36: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 32

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Use the graphic to explain that the primary key in this table ID will automatically have an index created.

Page 37: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 33

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

The decision to create indexes is a global, high-level decision. Creation and maintenance of indexes is often a task for the database administrator. For a SELECT statement to use an index, it must have a WHERE clause that keys on the index column where the index column is not part of a function (like uppercasing, etc.). A ROWID is a hexadecimal string representation of the row address containing the block identifier, row location in the block, and database file identifier. The fastest way to access any particular row is by referencing its ROWID. Ask students to give an example of a unique constraint. Possible answer: For the DJ on Demand database, a unique constraint may be that no staff member's email and last name can be the same as another member's email and last name.

Page 38: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 34

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Ask students to execute the command to create an index on the title column in the DJ on Demand table. Confirm the index was created by querying the INDEXES in the data dictionary. CREATE INDEX d_cds_idx ON d_cds(title); SELECT index_name FROM USER_INDEXES; SELECT ic.index_name, ic.column_name, ic.column_position col_pos,ix.uniqueness FROM user_indexes ix, user_ind_columns ic WHERE ic.index_name = ix.index_name AND ic.table_name = 'D_CDS';

Page 39: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 35

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Review each item on the list. This is an important list for students to know and understand.

Page 40: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 36

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Review each item on the list. This is an important list for students to know and understand.

Page 41: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 37

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Ask students to give an example where a composite (multiple column) index may be useful. Possible answer: When two or more columns are searched as a unit. For example: create index artists_name_ind on artists(fname, lname)

Page 42: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 38

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

To illustrate the join condition shown, ask students to execute the query in SQL Workshop SQL Command Processor or view the indexes using the HTML DB Data Browser Indexes icon.

Page 43: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 39

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Ask students to enter the CREATE INDEX code shown and execute the SELECT * statement.

Page 44: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 40

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Let students know that to create a function-based index in their own schema, they must have the CREATE INDEX and QUERY REWRITE system privileges. To create the index in another schema or on another schema’s table, they must have the CREATE ANY INDEX and GLOBAL QUERY REWRITE privileges. The table owner must also have the EXECUTE object privilege on the functions used in the function-based index.

Page 45: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 41

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Ask students to DROP the indexes just created.

Page 46: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 42

Tell Me / Show Me

Tell Me / Show Me

Page 47: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 43

Tell Me / Show Me

Tell Me / Show Me

Tell Me / Show Me

Demonstrate creating a synonym and have students create a synonym for one of their copy_tablenames. Note: An insufficient privileges error occurs when using the CREATE PUBLIC SYNONYM. CREATE SYNONYM is allowed. Verify that the synonym was created using the Data Browser feature on the HTML DB SQL Workshop page. Then have students DROP SYNONYM and confirm in HTML DB SQL.

Page 48: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 44

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 1. CREATE INDEX cd_number_idx ON d_track_listings(cd_number); There are two ways to confirm that the index was created. The first way is to use the Data Browser to find a database object with type=INDEX and name=CD_NUMBER_IDX. The second way is to query the data dictionary tables. Below is a sample query using the tables, USER_INDEXES and USER_IND_COLUMNS. SELECT ic.index_name, ic.column_name, ic.column_position col_pos,ix.uniqueness FROM user_indexes ix, user_ind_columns ic WHERE ic.index_name = ix.index_name AND ic.table_name = 'D_TRACK_LISTINGS';

Page 49: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 45

2. SELECT ic.index_name, ic.column_name, ic.column_position col_pos,ix.uniqueness FROM user_indexes ix, user_ind_columns ic WHERE ic.index_name = ix.index_name AND ic.table_name = 'D_SONGS'; An alternative solution using the join statement is: SELECT index_name, ic.column_name, ic.column_position As col_pos, ix.uniqueness FROM user_indexes ix JOIN user_ind_columns ic USING (index_name) WHERE ic.table_name = 'D_SONGS'; 3. SELECT index_name, table_name, uniqueness FROM user_indexes WHERE table_name = 'D_EVENTS'; 4. CREATE SYNONYM dj_tracks FOR d_track_listings; 5. CREATE INDEX lower_d_partners_idx ON d_partners (LOWER(last_name)); SELECT * FROM d_partners WHERE LOWER(last_name) = 'tsang';

Page 50: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 46

Lesson 5 - Practice Exercises and Review

Lesson 5 - Practice Exercises and Review

Lesson Preparation

Use the Study Guides and Vocabulary to review. Students should complete the review questions in this lesson. Review the answers and concepts associated with each problem.

What to Watch For None.

Connections None.

Page 51: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 47

What Will I Learn?

What Will I Learn?

Page 52: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 48

Why Learn It?

Why Learn It?

Page 53: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 49

Tell Me / Show Me

Tell Me / Show Me

Page 54: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 50

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 1. table, view, sequence, index, synonym 2. Some numbers were cached and there was a system failure. The sequence is being used by someone else on a different table. 3. INSERT INTO employees(employee_id, department_id, first_name, last_name....) VALUES(employee_id.NEXTVAL, department_id.CURRVAL); 4. c. my_SEQ.CURRVAL

Page 55: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 51

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 5. a. Ensure that primary-key values will be unique and consecutive b. Ensure that numbers will be unique even though gaps may exist c. Use a range of numbers and optionally cycled through them again d. Set a fixed interval for successive numbers 6. d. Change the interval of the sequence 7. True

Page 56: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 52

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 8. False 9. True 10. b. To allow DBAs to make the specified object accessible to all users

Page 57: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 53

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 11. b. 10 12. a. cycle

Page 58: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 54

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 13. b. CREATE SYNONYM george_songs FOR george.copy_d_songs; 14. a. The table is updated often

Page 59: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 55

Try It / Solve It

Try It / Solve It

Try It / Solve It

Answers: 15. b. primary key c. unique key

Page 60: Instructor Guide Database Programming - Section 12 - Oracleacademy.oracle.com/pages/docs_pdfs_zip/2004_2005_curriculum/pdf… · Database Programming - Section 12 ... Have students

Copyright © Oracle, 2004. All rights reserved.

Database Programming - Section 12 Page 56