SGBD.2ASIR Activity 2.1 Data Dictionary
SGBD.2ASIR Activity 2.1 Data Dictionary
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
Page 1 | 27
Description
Delivery format:
• In this activity we are going to make queries on the tables of the Oracle data dictionary
oftwo users:
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.
Page 3 | 27
Then write and test the following Oracle dictionary queries in SqlDeveloper or SQL * Plus.
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.
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.
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.
Information of dba_constraints
The DBA_CONSTRAINTS view in Oracle provides information about all constraints defined on tables and
views in the database.
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.
Get the owner, table name, tablespace name of all the tables that are
owned by user HR
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
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
FROM SYS.DBA_TAB_COLUMNS
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
Get the total number of rows of all the tables owned by user HR
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
Page 11 | 27
Search the online documentation and bd for information about what views that start with ALL are.
Query to see all Oracle dictionary views that start with ALL
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
Page 13 | 27
Query that shows the constraints and the affected columns of the EMPLOYEES table of the HR user
Search the online documentation and bd for information about what views that begin with USER are.
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
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.
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
Query that shows how many objects exist for each type, for the HR user.
Page 19 | 27
Modify the previous query so that it shows ONLY those objects whose
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
Page 22 | 27
Query like the previous one but that only shows the columns affected by some constraint, with the name
of said constraints
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
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
Information of v$system_parameter
Page 25 | 27
Screenshot with the results
Information of v$instance
Query that shows the user, machine and program of the sessions opened in the database ordered by user
Query that shows, of the general Oracle parameters, the value of the parameter that indicates the location
of the control files ( control_files)
Query that shows, from the general Oracle parameters, the value of the parameter that indicates the name
of the database
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