0% found this document useful (0 votes)
7 views14 pages

Database 4th Lab Notes

The document provides lab notes on database management, focusing on the MetaBase and its structure, including various views and tables accessible to users. It outlines SQL commands for exploring database objects, user privileges, and metadata related to tables such as STUDENT and ENROLLMENT. Additionally, it includes steps to verify foreign keys, list constraints, and gather information about the EXAM_RESULT table.

Uploaded by

Ai Cha
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)
7 views14 pages

Database 4th Lab Notes

The document provides lab notes on database management, focusing on the MetaBase and its structure, including various views and tables accessible to users. It outlines SQL commands for exploring database objects, user privileges, and metadata related to tables such as STUDENT and ENROLLMENT. Additionally, it includes steps to verify foreign keys, list constraints, and gather information about the EXAM_RESULT table.

Uploaded by

Ai Cha
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/ 14

Database 4th Lab Notes

MetaBase : contains the description of all objects of the databases (index , views ,
tables , users ....) , maanged by the DBMS , itself is orgnised as a database , most
of the tablesin this dictionary cannot be modfied by the usrs (only the adminstrator)
but are authorized to be explored .
The tables of the dictionary are usually encrypted . however, their content is
accessible through views. There are mainly four types of views :

1. Connect as System and List the “DICT” Catalog


1. Launch SQL*Plus and log in as the SYSTEM user:

CONNECT system/password@your_database;

2. List the DICT catalog:


```sql
SELECT * FROM DICT;
```

3. Find the number of instances:


4. View the structure of the DICT catalog:

DESC DICT;

2. Role and Structure of Specific Tables/Views


ALL_TAB_COLUMNS: Information about all table columns the user has access to.

DESC ALL_TAB_COLUMNS;
USER_USERS: Information about the currently connected user.

```sql

DESC USER_USERS;
```
ALL_CONSTRAINTS: Metadata about constraints in tables.

DESC ALL_CONSTRAINTS;

![[Pasted image 20250111164004.png]]


- **USER_TAB_PRIVS**: Privileges granted on tables.
```sql
DESC USER_TAB_PRIVS;
```
![[Pasted image 20250111164040.png]]

---

### 3. Find the Username You Are Connected With

```sql
SELECT USER FROM DUAL;
4. Compare ALL_TAB_COLUMNS and
USER_TAB_COLUMNS
View structure of both:

```sql
DESC ALL_TAB_COLUMNS;
DESC USER_TAB_COLUMNS;
```
5. Verify Tables Created During the Previous Lab
SELECT TABLE_NAME FROM ALL_TAB_COLUMNS WHERE OWNER='DBASCHOOL'; --
has to be in capital letters (outputs all table names owned by the
user DBASchool)

SELECT * FROM ALL_TAB_COLUMNS WHERE OWNER='DBASCHOOL'; -- all info


about thoses tables

**6. List Tables of SYSTEM and DBASCHOOL


SYSTEM's tables:

SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = 'SYSTEM';

DBASchool's tables:

SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = 'DBASCHOOL';

7. Description of STUDENT and ENROLLMENT


Attributes

SELECT COLUMN_NAME , DATA_TYPE , DATA_LENGTH FROM USER_TAB_COLUMNS


where TABLE_NAME = 'STUDENT';
--Same for ENROLLMENT u can specify teh owner by AND OWNER =
'DBASCHOOL'
SELECT COLUMN_NAME , DATA_TYPE , DATA_LENGTH FROM USER_TAB_COLUMNS
WHERE TABLE_NAME = 'ENROLLMENT';

8. Verify Foreign Key EXAM and COURSE?

SELECT CONSTRAINT_NAME FROM USER_CONSTRAINTS WHERE CONSTRAINT_TYPE


= 'R' AND TABLE_NAME IN ('EXAM', 'COURSE');
9. List All Constraints

SELECT CONSTRAINT_NAME , CONSTRAINT_TYPE , TABLE_NAME FROM


USER_CONSTRAINTS;

10. Find All Information needed to recreate the


EXAM_RESULT

SELECT TABLE_NAME , COLUMN_NAME , DATA_TYPE , DATA_LENGTH FROM


USER_TAB_COLUMNS WHERE TABLE_NAME = 'EXAM_RESULT';
11. Privileges Granted to Admin

SELECT * FROM ALL_TAB_PRIVS WHERE GRANTEE = 'ADMIN';

OUTPUT

12. Roles Assigned to Admin


After connecting as 'sys' to get admin priviliges

SELECT GRANTED_ROLE FROM DBA_ROLE_PRIVS WHERE GRANTEE = 'ADMIN';


13. Objects Belonging to Admin
we use the all_objects table .

SELECT OBJECT_NAME, OBJECT_TYPE FROM ALL_OBJECTS WHERE OWNER =


'ADMIN';

14. Find the Owner of EXAM_RESULT Table

SELECT OWNER FROM ALL_TABLES WHERE TABLE_NAME = 'EXAM_RESULT';

15. Size of EXAM_RESULT Table


The USER_SEGMENTS view provides information about the storage allocated for the
segments (tables, indexes, etc.) owned by the current user.

SELECT SEGMENT_NAME, BYTES/1024 AS SIZE_KB


FROM USER_SEGMENTS
WHERE SEGMENT_NAME = 'EXAM_RESULT';
16. Check the effect produced by each of the
previous lab’s data definition commands on the
dictionary

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy