0% found this document useful (0 votes)
4 views

DAM Lecture # 5

Uploaded by

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

DAM Lecture # 5

Uploaded by

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

Lecture # 5

What Is DDL?
• DDL is a Data Definition Language that is used to define data
structures. For example: creating a table, and altering a table are
instructions in SQL.
• DDL is used to specify a database’s structure, which includes its
tables, views, indexes, and constraints.
• DDL commands come in the following types: CREATE, ALTER, DROP,
RENAME, and TRUNCATE.
• DDL statements only modify the database’s schema; they have no
direct effect on the data within the database.
• DDL declarations are irreversible and difficult to undo.
What is DML?
• DML is a Data Manipulation Language that is used to manipulate
data itself. For example: insert, update, and delete are instructions in
SQL.
• Inserting, updating, removing, and retrieving data from a database
are all possible with DML.
• DML commands come in the following types: SELECT, INSERT, UPDATE,
DELETE, and MERGE.
• DML statements have a direct impact on the database’s data.
• In the event of an error, data can be recovered thanks to the
reversibility of DML statements.
Database Schema

In Oracle, a schema is a logical container that groups together


database objects owned by a specific user.

It's essentially a private workspace within the database where a


user can create and manage tables, indexes, views, procedures,
functions, and other database objects
Figure
Key Points About Oracle
Schemas
Ownership: Each schema is owned by a database user.

Isolation: Objects within a schema are isolated from those in


other schemas, providing security and data integrity.

Organization: Schemas help organize database objects


logically, making them easier to manage and maintain.

Security: Access to schema objects can be controlled through


database user privileges and roles.
Oracle Table Spaces
• This is a logical structure, meaning that a tablespace is not a physical
object.
• A tablespace is made of 1 or more physical structures called datafiles.
• Each tablespace can have different characteristics, such as size and
how the size are managed.
• They are used to group segments (tables, indexes, etc) into logical
groups.
• For example, you may have accounting data in one tablespace and
reporting data in another. This does not have to be the case, though,
you are free to put whatever you like in the table spaces you create.
Why Use Tablespaces?
•Logical Organization: Tablespaces provide a logical way to organize
database objects, making it easier to manage and maintain.

•Physical Storage: Datafiles, the physical storage units, are assigned to


tablespaces. This separation between logical and physical storage allows
for flexible database design and administration.

•Performance Optimization: By strategically allocating different types of


data objects to specific tablespaces, you can optimize database
performance.

•Security: Tablespaces can be used to implement security measures by


controlling access to specific data.
Oracle Indexes
• Just like we have index present in the textbooks to help us find the
particular topic in the book, Oracle index behaves the same way.
• Indexes are used to search the rows in the oracle table quickly. If the
index is not present the select query has to read the whole table and
returns the rows. With Index, the rows can be retrieved quickly.
• Indexes are optional structures associated with tables and clusters. You
can create indexes on one or more columns of a table to speed
SQL statement execution on that table.
• Indexes are the primary means of reducing disk I/O ( refers to the speed
at which data is read or written to or from a physical disk) when properly
used.
Creating an Index in Oracle
• To create an index, you can use the following SQL statement:

• CREATE INDEX index_name ON table_name (column_name1,


column_name2, ...);
How to recreate the
Indexes/rebuild index in oracle?
• We can Use the ALTER INDEX … REBUILD statement to reorganize or
compact an existing index or to change its storage characteristics.

• The REBUILD statement uses the existing index as the basis for the
new one.
• ALTER INDEX … REBUILD is usually faster than dropping and re-
creating an index.
• SYNTAX:

Alter index <index name> rebuild ;


Alter index <index name> rebuild tablespace <name>;
How does Oracle decide about
the usage of index?
• Oracle decides whether to use an index or not depending
upon the query.
• Oracle can understand whether using an index will improve
the performance in the given query. If Oracle thinks using an
index will improve performance, it will use the index
otherwise it will ignore the index.
Example 1
• We have a table emp which contains emp_name,
salary,dept_no ,emp_no,date_of_joining and we have an index on
emp_name.
• Lets use the query:
• select * from emp where emp_name = 'John’;
• The above query will use the index as we are trying to get information
about a emp based on the name.
Example 2
• select * from emp;
• Result:
• The above query will not use index as we are trying to find all the
rows in the table and we don’t have where clause in the query
What are the Drawbacks of the
Indexes
• Indexes increase performance of select query, they can also decrease
performance of data manipulation.
• Many indexes on a table can slow down INSERTS and DELETES
drastically
• The more the indexes on the table, the more time inserts and delete
will take.
• Similarly every change to an indexed column will need a change to
index.

You might also like