Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 22 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
22
Dung lượng
120,45 KB
Nội dung
OracleDataDictionary 10 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć2 OracleDataDictionary 10Ć3 Objectives The Oracledatadictionary 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 datadictionary views a user may access. D Query data from the data dictionary. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć4 OracleDataDictionary 10Ć5 Overview The Oracledatadictionary 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 datadictionary is updated and maintained by the Oracle7 Server. All datadictionary 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 datadictionary 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. Datadictionary Collection of tables created and maintained by the Oracle7 Server, such as USER_OBJECTS, that contain information about the database. Example DataDictionary 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 DataDictionary Uses The datadictionary is a reference for all database users. It is a valuable source of information for end users, application designers, and DBAs. The datadictionary is also critical for the operation of the Oracle7 Server because the database relies on the datadictionary to record and verify information about itself. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć6 OracleDataDictionary 10Ć7 Querying the DataDictionary You can query the datadictionary by issuing a SQL SELECT statement. Depending on your privileges, you can query various views. View Classes Datadictionary 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 datadictionary views do not use the prefixes listed above. These include synonyms for views with long names. View Name Description DICTIONARY Lists all datadictionary 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 OracleDataDictionary 10Ć9 Querying the DataDictionary continued Example The DICTIONARY view lists all datadictionary 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 datadictionary 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 datadictionary 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 OracleDataDictionary 10Ć15 10Ć16 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Summary The datadictionary is a set of tables that the user can query through views The datadictionary holds all the data about the database Write a SELECT statement to display the contents of the datadictionary views Frequently Accessed DataDictionary Views D DICTIONARY D DICT_COLUMNS... OracleDataDictionary 10Ć17 10Ć18 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Practice Overview In this practice, you will access the datadictionary views to verify information about your tables Practice Contents D Querying the datadictionary to view table information D Viewing constraint information from the datadictionaryOracleDataDictionary 10Ć19 10Ć20 Introduction to Oracle: ... page OracleDataDictionary 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 datadictionary 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 DataDictionary 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 datadictionary for a specific topic by querying the COMMENTS column in the DICTIONARY view Find all datadictionary views pertaining to the keyword Grant COLUMN table_name... ALL_COL_PRIVS_MADE Grants on columns for which th e user is owner or grantor ALL_COL_PRIVS_RECD Grants on columns for which th e user, PUBLIC or enabled role is the grantee 20 rows selected OracleDataDictionary 10Ć11 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... 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 OracleDataDictionary 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 datadictionary 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... Viewing constraint information from the datadictionaryOracleDataDictionary 10Ć19 10Ć20 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder Practice 10 1 Select all the views from the datadictionary pertaining to Table You can adjust the column formats by using the SQL*Plus COLUMN command If you want to interrupt your query, you can cancel it by pressing [CTRL]+[C] on your PC keyboard... querying the COMMENTS column in the DICTIONARY view Find all datadictionary 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 . Oracle Data Dictionary 10 Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć2 Oracle Data Dictionary 10Ć3 Objectives The Oracle data dictionary. Introduction to Oracle: SQL and PL/SQL Using Procedure Builder10Ć6 Oracle Data Dictionary 10Ć7 Querying the Data Dictionary You can query the data dictionary