12.Data Dictionary

download 12.Data Dictionary

of 16

Transcript of 12.Data Dictionary

  • 8/4/2019 12.Data Dictionary

    1/16

    Data Dictionary Nature of a Data Dictionary (DD) Rationale for a DD

    Structure of a DD Typical DD Contents

    Using SQL to View DD in Oracle

    grant and revoke Statements

  • 8/4/2019 12.Data Dictionary

    2/16

    Nature of a DD A database contains information about entities

    of interest to users in an organization When created, the database itself becomes

    an entity about which information must bekept for various data administration purposes

    Data dictionary(or system catalog)is adatabase about the database

    Contents of a DD are commonly referred to as

    metadata DD can be updated, queried much as aregular database

    DBMS often maintains the DD

  • 8/4/2019 12.Data Dictionary

    3/16

    Rationale for a DD Provides a summary of the structure of thedatabase helps DBA manage the database

    informs users of database scope Facilitates communication between users and

    database administrators

    Allows the DBMS to manage the creation,

    access, and modification of tables and theircomponents

  • 8/4/2019 12.Data Dictionary

    4/16

    Structure of a DD DD can be integratedwith the DBMS or

    stand-alone

    Relational systems all have some form ofintegrated DD (e.g., Oracle)

    Integrated DD is usually active, meaning it isautomatically updated to reflect changes in

    the database A stand-alone DD is not directly linked to the

    database and must be updated manually

  • 8/4/2019 12.Data Dictionary

    5/16

    Typical DD Contents Data elements

    names, data type

    Tables owner, creation date, access specifications, size

    Indexes name, attributes involved, creation date

    Authorized users names, type(s) of access

    Integrity Constraints

  • 8/4/2019 12.Data Dictionary

    6/16

    Using SQL to View DD in Oracle

    Some Oracle DD (Catalog) Tables SYS.OBJ$

    contains, for each database object, such data asobject name, owner (number), creation time

    Can view details with describe sys.obj$

    Sample query

    select name, ctimefrom sys.obj$

    where ctime > 01-feb-02;

  • 8/4/2019 12.Data Dictionary

    7/16

    SYS.COL$ Contains, for each column, such data as data type,

    table, whether nulls are allowed, and position in

    table

    View with describe sys.col$

    Sample query select obj#

    from sys.col$

    where upper(name) = city;

    Using SQL to View DD in Oracle

    Some Oracle DD (Catalog) Tables

  • 8/4/2019 12.Data Dictionary

    8/16

    SYS.IND$

    Contains the indexes defined for every table

    describe sys.ind$

    select i.ind#, o.name

    from sys.ind$ i, sys.obj$ o

    where i.obj# = o.obj#;

    select count(*) from sys.ind$;

    SYS.USER$

    Contains name, password, and other informationabout each user

    select password from sys.user$

    where name = jparsons;

    Using SQL to View DD in Oracle

    Some Oracle DD (Catalog) Tables

  • 8/4/2019 12.Data Dictionary

    9/16

    SYS.VIEW$

    Contains information about defined views

    describe sys.view$

    select * from sys.view$;

    SYS.TAB$

    Contains administrative information about tables

    There are many additional system tables inthe Oracle data dictionary

    Using SQL to View DD in Oracle

    Some Oracle DD (Catalog) Tables

  • 8/4/2019 12.Data Dictionary

    10/16

    COMMENT ON statement

    Can put comments on each database object as ageneral description of that object

    comment ontable orders

    is Contains all unfilled orders;

    comment on

    column orders.dollars

    is Total value = qty*products.price;

    Using Comments to DescribeDatabase Objects

  • 8/4/2019 12.Data Dictionary

    11/16

    select comment$ from sys.com$

    where col# is null

    and obj# in

    (select obj# from sys.obj$where name = orders);

    The DD contains a lot of information we may notwant to be generally available

    Possible to create views such that users can seedata related only to tables created by themselves

    Tables owned by sys (the DBA) are not generallyavailable to ordinary users

    Using Comments to DescribeDatabase Objects

  • 8/4/2019 12.Data Dictionary

    12/16

    Sample Queries on the DD

    Can a particular user create a table with aparticular name, or has s/he already usedthat name?

    Which views are based on more than one

    base table? Finally, one to show you we have not covered

    everything there is to know ... How much storage space is still free in the entire

    database? select sum(f.length*ts.blocksize)

    from sys.ts$ ts, sys.fet$ f

    where ts.ts# = f.ts#;

  • 8/4/2019 12.Data Dictionary

    13/16

    grant statementconnect, dba, resource

    Several versions of grant statement

    connect: allows new users to have access to Oracle

    grant connect to jeff

    identified by pwxx4r; resource: allows users to create their own tables

    with all privileges (see later) on those tables

    grant resource to veda, greenthing;

    /* Assumes veda and greenthing exist dba: execute all commands on all database objects

    grant dba to mom, dick, mary

    identified by dad, ehsg, plymouth;

  • 8/4/2019 12.Data Dictionary

    14/16

    grant StatementTable Privileges

    Allows owner of a table to control access by other

    database users to data in the tables

    Types of access include

    select: allows users to select from specifiedtable

    insert, delete, update, index, alter

    references: allows user to define foreign keys

    on specified table all: allows user all privileges specified above

    with grant option clause allows recipient to

    pass the privilege on

  • 8/4/2019 12.Data Dictionary

    15/16

    grant insert on orders to paulwith grant option;

    grant insert, delete, update

    on customers to marilyn;

    grant update (quantity)

    on products

    to anil;

    grant select on agents to public;/* Provides every user the

    privilege */

    grant StatementTable Privileges

  • 8/4/2019 12.Data Dictionary

    16/16

    All table privileges are stored in a table calledTABAUTH$ with primary key SEQUENCE#

    Update privileges on columns are stored inCOLAUTH$

    revoke statement withdraws privilegespreviously granted (connect, dba, resource, tableprivileges)

    revoke dba from dick;

    revoke resource from greenthing; revoke delete on customers frommarilyn;

    revoke select on agents from public;

    grant and revoke Statements