1. Trang chủ
  2. » Công Nghệ Thông Tin

Tài liệu oracle data dictionary docx

22 531 2

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 22
Dung lượng 138,05 KB

Nội dung

Oracle Data Dictionary 10 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć2 Schedule: Timing Topic 20 minutes Lecture 15 minutes Practice 35 minutes Total Class Management Note: Files required for this lesson are: Demonstration: l10tab.sql, l10obj2.sql, l10cons.sql Practice: None Oracle Data Dictionary 10Ć3 Objectives The Oracle data dictionary is one of the most important components of the Oracle7 Server. It consists of a set of tables and views that provide a read-only reference to the database. At the end of this lesson, you should be able to D Describe the data dictionary views a user may access. D Query data from the data dictionary. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć4 Oracle Data Dictionary 10Ć5 Overview The Oracle data dictionary is one of the most important components of the Oracle7 Server. It is created when a database is created. Whenever the database is in operation, the data dictionary is updated and maintained by the Oracle7 Server. All data dictionary tables are owned by the SYS user. The base tables are rarely accessed directly because the information in them is not easy to understand. Therefore, users typically access data dictionary views because the information is presented in a format that is easy for them to understand. Tables Within the Oracle7 Database Tables Description User tables Collection of tables created and maintained by the user, such as S_EMP, that contain user information. Data dictionary Collection of tables created and maintained by the Oracle7 Server, such as USER_OBJECTS, that contain information about the database. Example Data Dictionary Contents D Names of Oracle7 Server users D Privileges granted to users D Database object names (for example, tables, views, and indexes) D Table constraints D Auditing information, such as who has accessed or updated specified database objects Data Dictionary Uses The data dictionary is a reference for all database users. It is a valuable source of information for end users, application designers, and DBAs. The data dictionary is also critical for the operation of the Oracle7 Server because the database relies on the data dictionary to record and verify information about itself. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć6 Class Management Note: The V$ views are initially accessible to the DBA. They are also special in that they are not stored in disk files, but are based on information constantly held in memory. In order for users to view the V$ tables, the DBA must assign them to the MONITORER role. Oracle Data Dictionary 10Ć7 Querying the Data Dictionary You can query the data dictionary by issuing a SQL SELECT statement. Depending on your privileges, you can query various views. View Classes Data dictionary view names reflect their intended use. There are four categories of views; each category has a distinct prefix. Prefix Description USER_ Contains objects owned by the user. For example, views with this prefix allow the user to display information about tables created by the user and privileges granted by the user. ALL_ Accesses objects to which the user has been granted access rights, in addition to objects owned by the user. DBA_ Allows users with the DBA privilege to access any object in the database. V$ Displays database server performance and locking. Initially available only to the DBA. Additional Views Several data dictionary views do not use the prefixes listed above. These include synonyms for views with long names. View Name Description DICTIONARY Lists all data dictionary tables, views, and synonyms. TABLE_PRIVILEGES Grants on objects for which the user is the grantor, grantee, or owner. IND Is a synonym for USER_INDEXES. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć8 Class Management Note: DEMO: l10tab.sql PURPOSE: Display all tables owned by the user. DEMO: l10obj2.sql PURPOSE: Display all objects owned by the user based on a supplied value. This script uses a substitution parameter and the UPPER function so that you can enter only part of the object type and to make the comparison case-insensitive. 1.Enter: START l10obj2 2.At the prompt for the object, enter: tab 3.Execute the file again. At the prompt, enter: seq 4.Edit the file to show students the SELECT statement. Oracle Data Dictionary 10Ć9 Querying the Data Dictionary continued Example The DICTIONARY view lists all data dictionary views accessible to the user with a brief description of the object in a comment column. You can also reference the synonym for the view, DICT. SQL> SELECT * 2 FROM DICTIONARY; Example You can display the structure of any data dictionary view by using the SQL*Plus DESCRIBE command. Display the structure of USER_OBJECTS. SQL> DESCRIBE user_objects Name Null? Type ------------------------------ -------- ------------ OBJECT_NAME VARCHAR2(128) OBJECT_ID NUMBER OBJECT_TYPE VARCHAR2(13) CREATED DATE LAST_DDL_TIME DATE TIMESTAMP VARCHAR2(75) STATUS VARCHAR2(7) Example To view a description of each column in data dictionary tables and views, query the DICT_COLUMNS view. SQL> SELECT column_name, comments 2 FROM dict_columns 3 WHERE table_name = ’USER_OBJECTS’; For more information, see Oracle7 Server SQL Language Quick Reference, Release 7.3. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć10 [...]... USERID 8 rows selected Oracle Data Dictionary 10Ć15 10Ć16 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Summary The data dictionary is a set of tables that the user can query through views The data dictionary holds all the data about the database Write a SELECT statement to display the contents of the data dictionary views Frequently Accessed Data Dictionary Views D DICTIONARY D DICT_COLUMNS... Oracle Data Dictionary 10Ć17 10Ć18 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Practice Overview In this practice, you will access the data dictionary views to verify information about your tables Practice Contents D Querying the data dictionary to view table information D Viewing constraint information from the data dictionary Class Management Note: Duration: 15 minutes Oracle Data. .. name Oracle Data Dictionary 10Ć13 10Ć14 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Checking Constraints on a Table continued View the names of the columns involved in constraints by querying the USER_CONS_COLUMNS data dictionary view This view is especially useful for constraints that use the system-assigned name Example Display the column constraint information in the data dictionary. ..Querying the Data Dictionary continued Example Display the types of objects that the user owns SQL> SELECT 2 FROM DISTINCT object_type user_objects; Example You can search the data dictionary for a specific topic by querying the COMMENTS column in the DICTIONARY view Find all data dictionary views pertaining to the keyword Grant COLUMN table_name... grantor ALL_COL_PRIVS_RECD Grants on columns for which th e user, PUBLIC or enabled role is the grantee 20 rows selected Oracle Data Dictionary 10Ć11 Class Management Note: DEMO: l10cons.sql PURPOSE: Display the constraints on the S_EMP table 1 Describe the USER_CONSTRAINTS data dictionary view 2 Execute the script Enter: START l10cons 3 Describe what each column represents Emphasize the ease of determination... view table information D Viewing constraint information from the data dictionary Class Management Note: Duration: 15 minutes Oracle Data Dictionary 10Ć19 10Ć20 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Practice 10 1 Select all the views from the data dictionary pertaining to Table You can adjust the column formats by using the SQL*Plus COLUMN command If you want to interrupt your query,... parameter for the table name Save the query as p10q4.sql Execute the script to confirm the constraints for the tables you created in Practice 9, DEPARTMENT and EMPLOYEE tables Oracle Data Dictionary 10Ć21 10Ć22 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder ... Note: If you did not complete Practice 9, Exercise 2 and Exercise 3, you can invoke scripts p9q2.sql and p9q3.sql to create DEPARTMENT table and EMPLOYEE table respectively 3 Query the USER_OBJECTS data dictionary to see information about the tables you created in Practice 9, DEPARTMENT and EMPLOYEE tables 4 Create a script to execute a generic query to confirm the constraints for the tables you have... querying the COMMENTS column in the DICTIONARY view Find all data dictionary views pertaining to the keyword Grant COLUMN table_name FORMAT A20 COLUMN comments FORMAT A30 SQL> SELECT 2 FROM 3 WHERE * dictionary LOWER(comments) LIKE ’%grant%’; TABLE_NAME COMMENTS -ALL_COL_PRIVS Grants on columns for which th e user is the grantor, grantee , owner, or an enabled role or PUBLIC... Question: Ask students how to change this script to allow a query for constraints on any table Answer: Modify the WHERE clause to read: WHERE table_name LIKE UPPER (’%&table_name%’) 10Ć12 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Checking Constraints on a Table After creating a table, you can confirm its existence by issuing a DESCRIBE command The only constraint you can verify is . the SELECT statement. Oracle Data Dictionary 10Ć9 Querying the Data Dictionary continued Example The DICTIONARY view lists all data dictionary views accessible. dictionary. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć4 Oracle Data Dictionary 10Ć5 Overview The Oracle data dictionary is one of the

Ngày đăng: 21/12/2013, 06:17

TỪ KHÓA LIÊN QUAN