Sgbd.2asir Activity 2.1 Español
Sgbd.2asir Activity 2.1 Español
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 | 30
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 | 30
Activity 1.1. Queries about DBA views
Documentation of dba_tablespaces
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.
The data dictionary views, also known as catalog views, let you monitor the state of the database in real
time
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.
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 | 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.
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 | 30
Get the name of all the tablespaces of the database
By default, the tablespace where tables are stored in an Oracle Database is the USERS tablespace.
Page 7 | 30
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
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.
Obtenga el número total de filas de todas las tablas propiedad del usuario HR
Page 13 | 30
Screenshot of the results
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.
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
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
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.
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
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.
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
Consulta que muestra cuántos objetos existen para cada tipo, para el usuario de RRHH.
Page 22 | 30
Modify the previous query so that it shows ONLY those objects whose
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
Page 25 | 30
Consulta como la anterior pero que solo muestra las columnas afectadas por alguna restricción,
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
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 28 | 30
Run desc or describes of this view. Capture an image of its structure
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)
Page 29 | 30
Query that shows, from the general Oracle parameters, the value of the parameter that indicates the name
of the database
Question: Can you access the view that shows if the database is open from the HR user? Why?
Page 30 | 30