0% found this document useful (0 votes)
10 views27 pages

SGBD.2ASIR Activity 2.1 Data Dictionary

Uploaded by

dani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views27 pages

SGBD.2ASIR Activity 2.1 Data Dictionary

Uploaded by

dani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

2nd ASIR - Database Management Systems

Course 2020-2021

ID
Name Database Management Systems System and
Cycle Network Administration 2
No. Sessions

Start date
Deliver date

Short description
Short description Oracle Dictionary Research 1 PC per person
Necessary material

Information sources • Class transparencies


• Information on the web
goals
• Know the main tables of the Oracle dictionary.
• Extract information from the Oracle dictionary by constructing queries.

Page 1 | 27
Description

Delivery format:

• The name of the document is:


SGBD.2ASIR_Aactivity_2.1_Data_Dictionary

• The work will be done in Word format.

• The work will be delivered in the folder Evaluation 1 shared on OneDrive.

• In this activity we are going to make queries on the tables of the Oracle data dictionary
oftwo users:

• System: schema with DBA role


• HR: sample schema embedded in Oracle

Activity 1

Querying the Oracle Dictionary Views of the System User (DBA Role)

As the System user has a DBA role, from there we can consult the v $ and DBA_ views of the Oracle
dictionary, as well as, of course, the ALL and USER views.

The following image shows the data model of the Oracle dictionary DBA views.

Page 2 | 27
Activity 1.1. Queries about DBA views

Documentation of dba_tablespaces
DBA_TABLESPACES describes all tablespaces in the database.

Run desc or describes of this view. Capture an image of its structure

Page 3 | 27
Then write and test the following Oracle dictionary queries in SqlDeveloper or SQL * Plus.

Query to see all Oracle dictionary views


The data dictionary views, also known as catalog views, let you monitor the state of the database in real
time

Screenshot with the results

Query to see all Oracle dictionary views that start with DBA

To see all Oracle dictionary views that start with "DBA", you can query the ALL_VIEWS or DICTIONARY
view in Oracle.

Screenshot with the results

Page 4 | 27
Next we are going to work with the following DBA type views:

dba_tablespaces

dba_tables

dba_tab_columns

dba_constraints

Search the online documentation and bd for information about the content of these views:

Information of dba_tables
DBA_TABLES describes all relational tables in the database. Its columns are the same as those
in ALL_TABLES.

Run desc or describes of this view. Capture an image of its structure

Page 5 | 27
Information of dba_tab_columns
The DBA_TAB_COLUMNS view in Oracle provides detailed information about all columns in all tables,
views, and clusters in the database.

Run desc or describes of this view. Capture an image of its structure

Information of dba_constraints
The DBA_CONSTRAINTS view in Oracle provides information about all constraints defined on tables and
views in the database.

Run desc or describes of this view. Capture an image of its structure

Page 6 | 27
Get the name of all the tablespaces of the database
To retrieve the names of all the tablespaces in the Oracle database.

Screenshot of the results

Question: which the tablespace where tables are stored by default?


By default, the tablespace where tables are stored in an Oracle Database is the USERS tablespace.

Get the owner, table name, tablespace name of all the tables that are
owned by user HR

Screenshot of the results

Page 7 | 27
Get the table name, tablespace name, status and number of
rows of all the tables whose table name ends by IONS and are
owned by user HR

Screenshot of the results

Page 8 | 27
Get the owner, table name, column names, data type and
length of the columns of the table
EMPLOYEES owned by HR and whose column identifier is
greater than 5 and lower than 10 ordered by column identifier in
descendant order

SELECT OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_LENGTH, COLUMN_ID

FROM SYS.DBA_TAB_COLUMNS

WHERE OWNER = 'HR' AND TABLE_NAME = 'EMPLOYEES' AND

COLUMN_ID BETWEEN 5 AND 10

ORDER BY COLUMN_ID DESC

Screenshot of the results

Get the owner, table name, tablespace, column names, data type and data length of the columns of all the
database tables which are stored in the tablespace USERS

Page 9 | 27
Screenshot of the results

Get the owner, table name, column names, data type, constraint name and constraint type of the columns of all
the tables which are owned by user HR ordered by table name and column name

Screenshot of the results

Get the total number of rows of all the tables owned by user HR

Screenshot of the results

Page 10 | 27
Activity 1.2. Queries about ALL and USER views

Query that shows the owner, table name, tablespace and column data type and name of all tables that
contain the string "COMPANY" and sorting by owner, table and column identifier

Screenshot with the results

Page 11 | 27
Search the online documentation and bd for information about what views that start with ALL are.

ALL views documentation

Query to see all Oracle dictionary views that start with ALL

Screenshot with the results

Next we are going to work with the following ALL views from the SYSTEM user.

all_tables
all_tab_columns
all_users

Page 12 | 27
all_cons_columns
all_views

Query that shows all users in the database

Screenshot with the results

Page 13 | 27
Query that shows the constraints and the affected columns of the EMPLOYEES table of the HR user

Screenshot with the results

Search the online documentation and bd for information about what views that begin with USER are.

USER views documentation


Las vistas que comienzan con "USUARIO" en el contexto de una base de datos generalmente se refieren
a vistas de sistema o catálogo relacionadas con objetos definidos por el usuario o metadatos relacionados
con el usuario. Por ejemplo, en bases de datos SQL como SQL Server, dichas vistas (por ejemplo,
USER_TABLES o USER_VIEWS) devuelven información sobre los objetos que crean los usuarios, como
tablas, vistas e índices.

Query to see all Oracle dictionary views that start with USER

Page 14 | 27
Select *
from SYS.ALL_VIEWS
Where view_name like
'USER%'
Screenshot with the results

Page 15 | 27
Next we are going to work with the following views of type USER from the HR user.

user_objects user_tables

user_tab_columns

user_constraints

user_cons_columns

user_role_privs

Search the online documentation and bd for information about the content of these views:

Information of user_objects
View provides detailed information about all the objects owned by the current user.

Run desc or describes of this view. Capture an image of its structure Describe user_objects

Information of user_tables
View provides detailed information about all the tables owned by the current user.

Run desc or describes of this view. Capture an image of its structure Describe user_tables

Page 16 | 27
Information of user_role_privs
View provides information about the roles granted to the current user

Run desc or describes of this view. Capture an image of its structure

Page 17 | 27
Question: Do USER views have an OWNER column? Reason the answer

USER: SYSTEM
SELECT * FROM USER_TABLES

Query that shows all table type objects that belong to the SYSTEM user. The name of the object, the
object type, the creation date and its status should be displayed. Sort by creation date.

SELECT OBJECT_NAME, OBJECT_TYPE,


CREATED, STATUS
FROM USER_OBJECTS
WHERE OBJECT_TYPE = 'TABLE'
ORDER BY CREATED

Screenshot with the results

Page 18 | 27
Query that shows the tables owned by the current user (HR / SYSTEM). Show table name, tablespace,
tablespace status and number of records sorted by table name

SELECT TABLE_NAME, TABLESPACE_NAME, STATUS, NUM_ROWS FROM USER_TABLES


ORDER BY TABLE_NAME

Screenshot with the results

Query that shows how many objects exist for each type, for the HR user.

SELECT COUNT (*), OBJECT_TYPE


FROM USER_OBJECTS
GROUP BY OBJECT_TYPE

Page 19 | 27
Modify the previous query so that it shows ONLY those objects whose

quantity is greater than 5

SELECT COUNT (*), OBJECT_TYPE


FROM USER_OBJECTS
GROUP BY OBJECT_TYPE
HAVING COUNT (*)> 5

Page 20 | 27
Query that shows from the DEPARTMENTS table the name of the table, name of the tablespace, name of
the columns, data type, length and if the column is nullable OR NOT ordered by the column identifier

Page 21 | 27
SELECT
A.TABLE_NAME, A.TABLESPACE_NAM
E, B.COLUMN_NAME, B.DATA_TYPE,
B.DATA_LENGTH, B.NULLABLE
FROM USER_TABLES A
INNER JOIN USER_TAB_COLUMNS B ON
A.TABLE_NAME = B.TABLE_NAME
INNER JOIN USER_CONS_COLUMNS C ON
C.TABLE_NAME = B.TABLE_NAME
AND
C.COLUMN_NAME = B.COLUMN_NAME
WHERE
A.TABLE_NAME = 'DEPARTMENTS'
ORDER BY B.COLUMN_ID

Screenshot with the results

Page 22 | 27
Query like the previous one but that only shows the columns affected by some constraint, with the name

of said constraints

Screenshot with the results

Query showing HR user privileges

SELECT * FROM USER_ROLE_PRIVS

Screenshot with the results

Page 23 | 27
Page 24 | 27
Activity 1.3. Queries on V$ views

Search the online documentation and bd for information about what views that start with V$ are.

V $ views documentation

Query to see all Oracle dictionary views that start with V$

Screenshot with the results

Next we are going to work with the following views of type V$.

v$session

v$system_parameter

v$instance

Search the online documentation and bd for information about the content of these views:

Information of v$session

Run desc or describes of this view. Capture an image of its structure

Screenshot with the results

Information of v$system_parameter

Run desc or describes of this view. Capture an image of its structure

Page 25 | 27
Screenshot with the results

Information of v$instance

Run desc or describes of this view. Capture an image of its structure

Screenshot with the results

Query that shows the user, machine and program of the sessions opened in the database ordered by user

Screenshot with the results

Query showing general Oracle parameters

Screenshot with the results

Query that shows, of the general Oracle parameters, the value of the parameter that indicates the location
of the control files ( control_files)

Screenshot with the results

Query that shows, from the general Oracle parameters, the value of the parameter that indicates the name
of the database

Screenshot with the results

Query showing if the database is open

Page 26 | 27
Screenshot with the results

Question: Can you access the view that shows if the database is open from the HR user? Why?

Page 27 | 27

You might also like