0% found this document useful (0 votes)
9 views30 pages

Sgbd.2asir Activity 2.1 Español

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)
9 views30 pages

Sgbd.2asir Activity 2.1 Español

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/ 30

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 | 30
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 | 30
Activity 1.1. Queries about DBA views

Documentation of dba_tablespaces

DBA_TABLESPACES describes all tablespaces in the database.

Page 3 | 30
Run desc or describes of this view. Capture an image of its structure

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

Page 4 | 30
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

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 | 30
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 | 30
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.

Obtenga el propietario, el nombre de la tabla y el


nombre del espacio de tabla de todas las tablas que
pertenecen al usuario HR.

Page 7 | 30
Screenshot of the results

Obtenga el nombre de la tabla, el nombre del espacio de


tabla, el estado y el número de filas de todas las tablas cuyo
nombre de tabla termina en IONS y son propiedad del usuario
HR.

Screenshot of the results

Page 8 | 30
Obtenga el propietario, el nombre de la tabla, los
nombres de las columnas, el tipo de datos y la longitud
de las columnas de la tabla. EMPLEADOS propiedad de
HR y cuyo identificador de columna es mayor que 5 y
menor que 10 ordenados por identificador de columna
en orden descendente.

Page 9 | 30
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

Page 10 | 30
Obtenga el propietario, el nombre de la tabla, el espacio de
tabla, los nombres de las columnas, el tipo de datos y la
longitud de los datos de las columnas de todas las tablas de

Page 11 | 30
la base de datos que están almacenadas en el espacio de
tablas USUARIOS.

Page 12 | 30
Screenshot of the results

Obtenga el propietario, el nombre de la tabla, los nombres de las columnas, el tipo de datos, el
nombre de la restricción y el tipo de restricción de las columnas de todas las tablas que pertenecen
al usuario HR ordenadas por nombre de la tabla y nombre de la columna.

Screenshot of the results

Obtenga el número total de filas de todas las tablas propiedad del usuario HR

Page 13 | 30
Screenshot of the results

Activity 1.2. Queries about ALL and USER views

Consulta que muestra el propietario, nombre de la tabla, espacio de tabla y tipo de datos de
columna y nombre de todas las tablas que contienen la cadena "EMPRESA" y ordenando por
propietario, identificador de tabla y columna.

Screenshot with the results

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

Consulta para ver todas las vistas del diccionario de Oracle que comienzan con TODOS

Screenshot with the results

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

Page 15 | 30
all_tables
all_tab_columns
all_users
all_cons_columns
all_views

Query that shows all users in the database

Screenshot with the results

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

Consulta que muestra las restricciones y las columnas afectadas de la tabla EMPLEADOS del
usuario de HR.

Screenshot with the results

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.

Consulta para ver todas las vistas del diccionario de Oracle que comienzan con USUARIO

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

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:

Page 18 | 30
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 19 | 30
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 20 | 30
Question: Do USER views have an OWNER column? Reason the answer

USER: SYSTEM
SELECT * FROM USER_TABLES

Consulta que muestra todos los objetos tipo tabla que pertenecen al usuario SISTEMA. Se debe
mostrar el nombre del objeto, el tipo de objeto, la fecha de creación y su estado. Ordenar por fecha
de creación.

SELECT OBJECT_NAME, OBJECT_TYPE,


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

Screenshot with the results

Page 21 | 30
Consulta que muestra las tablas propiedad del usuario actual (HR/SISTEMA). Mostrar el nombre de
la tabla, el espacio de la tabla, el estado del espacio de la tabla y el número de registros ordenados
por nombre de la tabla
SELECT TABLE_NAME, TABLESPACE_NAME, STATUS, NUM_ROWS FROM USER_TABLES ORDER
BY TABLE_NAME

Screenshot with the results

Consulta que muestra cuántos objetos existen para cada tipo, para el usuario de RRHH.

SELECT COUNT (*), OBJECT_TYPE


FROM USER_OBJECTS
GROUP BY OBJECT_TYPE

Page 22 | 30
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 23 | 30
Consulta que muestra de la tabla DEPARTAMENTOS el nombre de la tabla, nombre del tablespace,
nombre de las columnas, tipo de datos, longitud y si la columna es anulable O NO ordenada por el
identificador de columna

Page 24 | 30
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 25 | 30
Consulta como la anterior pero que solo muestra las columnas afectadas por alguna restricción,

con el nombre de dichas restricciones

Screenshot with the results

Query showing HR user privileges

SELECT * FROM USER_ROLE_PRIVS

Screenshot with the results

Page 26 | 30
Page 27 | 30
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

Page 28 | 30
Run desc or describes of this view. Capture an image of its structure

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

Page 29 | 30
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

Screenshot with the results

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

Page 30 | 30

You might also like