SlideShare a Scribd company logo
1 of 28
Managing Tables
Objectives
After completing this lesson, you should be able to
do the following:
• Create tables using appropriate storage settings
• Control the space used by tables
• Analyze tables to check integrity and migration
• Retrieve information about tables from the data
dictionary
• Convert between different formats of ROWID
Storing User Data
Regular
table
Cluster
Partitioned
table
Index-organized
table
Structure of a Row
Database block
Row header
Column length
Column value
Oracle Data Types
CHAR(N), NCHAR(N)
VARCHAR2(N),
NVARCHAR2(N)
NUMBER(P,S)
DATE
RAW(N)
BLOB, CLOB,
NCLOB, BFILE
LONG, LONG RAW
ROWID, UROWID
VARRAY
TABLE
REF
Data type
Built-inUser-defined
Scalar RelationshipCollection
Data Types for Storing
Large Objects
LONG, LONG RAW
Single column per table
Up to 2 gigabytes
SELECT returns data
Data stored in-line
No object type support
Sequential access to chunks
LOB
Multiple columns per table
Up to 4 gigabytes
SELECT returns locator
Data stored in-line or out-of-line
Supports object types
Random access to chunks
ROWID Data Type
• Unique identifier for a row
• Used to locate a row
OOOOOO BBBBBBFFF RRR
Data object
number
Relative file
number
Row numberBlock number
ROWID Format
Restricted ROWID
• Can identify rows within a segment
• Needs less space
BBBBBBBB FFFFRRRR
Block number Row number File number
. .
Collections
• Collections are objects that contain objects.
• VARRAYs are ordered sets of elements containing
a count and a limit.
• Nested tables are tables with a column or
variable of the TABLE data type.
VARRAY Nested
table
Creating a Table
CREATE TABLE employee(
id NUMBER(7),
last_name VARCHAR2(25),
dept_id NUMBER(7))
PCTFREE 20 PCTUSED 50
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE data;
Temporary Tables
• The rows are private to the session.
• Tables retain data only for the duration of a
transaction or session.
• DML locks are not acquired on the data.
• DMLs do not generate redo logs.
ON COMMIT PRESERVE ROWS;
CREATE GLOBAL TEMPORARY TABLE employee_temp
AS SELECT * FROM employee;
Creating a Table: Guidelines
• Use a few standard extent sizes for tables to
reduce tablespace fragmentation.
• Use locally managed tablespaces to avoid
fragmentation.
• Use the CACHE clause for frequently used, small
tables.
Setting PCTFREE and PCTUSED
• Compute PCTFREE
(Average Row Size - Initial Row Size) * 100
Average Row Size
• Compute PCTUSED
Average Row Size * 100
100 - PCTFREE -
Available Data Space
Row Migration and Chaining
Before update After update
Pointer
Changing Storage and Block Utilization
Parameters
ALTER TABLE summit.employee
PCTFREE 30
PCTUSED 50
STORAGE(NEXT 500K
MINEXTENTS 2
MAXEXTENTS 100);
Manually Allocating Extents
ALTER TABLE summit.employee
ALLOCATE EXTENT(SIZE 500K
DATAFILE ‘/DISK3/DATA01.DBF’);
Nonpartitioned Table Reorganization
ALTER TABLE employee
MOVE TABLESPACE data1;
• Moves data into a new segment while preserving
indexes, constraints, privileges, and so on, on the
table
• Is being used to move a table to a different
tablespace or to reorganize extents
Free space
after delete
Unused block
Extent ID 0 1 2 3 4
Extent ID 0 1 2 3 4
Used block
High-Water Mark
After inserts:
After deletes:
High-water
mark
Finding the High-Water Mark:
DBMS_SPACE.UNUSED_SPACE
Extent ID 0 1 2 3 4
High-water mark
LAST_USED_EXTENT_FILE_ID,
LAST_USED_EXTENT_BLOCK_ID
TOTAL_BLOCKS
UNUSED_BLOCKS
Free space
after delete
Unused block
Before
deallocation
Used block
Deallocation of Unused Space
ALTER TABLE summit.employee
DEALLOCATE UNUSED;
After
deallocation
High-water
mark
Extent ID 43210
43210Extent ID
Truncating a Table
TRUNCATE TABLE summit.employee;
Extent ID 0 1
High-water
mark
Free space
Dropping a Table
DROP TABLE summit.department
CASCADE CONSTRAINTS;
Dropping a Column
ALTER TABLE employee
DROP COLUMN comments
CASCADE CONSTRAINTS CHECKPOINT 1000;
Remove a column from a table
• This removes the column length and data from
each row, freeing space in the data block.
• Dropping a column in a large table takes a
considerable amount of time.
Using the UNUSED Option
ALTER TABLE orders
SET UNUSED COLUMN comments
CASCADE CONSTRAINTS;
• Drop unused columns
ALTER TABLE orders
DROP UNUSED COLUMNS CHECKPOINT 1000;
• Mark a column as unused
• Continue to drop column operation
ALTER TABLE orders
DROP COLUMNS CONTINUE CHECKPOINT 1000;
Retrieving Table Information
DBA_OBJECTS
OWNER
OBJECT_NAME
OBJECT_ID
DATA_OBJECT_ID
CREATED
DBA_SEGMENTS
OWNER
SEGMENT_NAME
TABLESPACE_NAME
HEADER_FILE
HEADER_BLOCK
DBA_TABLES
OWNER
TABLE_NAME
PCT_FREE
PCT_USED
INITIAL_EXTENT
NEXT_EXTENT
MIN_EXTENTS
MAX_EXTENTS
PCT_INCREASE
CACHE
BLOCKS
EMPTY_BLOCKS
CHAIN_CNT
TEMPORARY
DURATION
DBA_EXTENTS
• OWNER
• SEGMENT_NAME
• EXTENT_ID
• FILE_ID
• BLOCK_ID
• BLOCKS
Retrieving Extent Information
DBMS_ROWID Package
Function Name
ROWID_CREATE
ROWID_OBJECT
ROWID_RELATIVE_FNO
ROWID_BLOCK_NUMBER
ROWID_ROW_NUMBER
ROWID_TO_ABSOLUTE_FNO
ROWID_TO_EXTENDED
ROWID_TO_RESTRICTED
Description
Creates a ROWID from individual components
Returns the object identifier for a ROWID
Returns the relative file number for a ROWID
Returns the block number for a ROWID
Returns the row number for a ROWID
Returns the absolute file number for a ROWID
Converts a ROWID from restricted to extended
Converts a ROWID from extended to restricted
Commonly used functions:
Summary
In this lesson, you should have learned how to:
• Create a table with appropriate storage and
block utilization parameters
• Control table storage
• Use the DBMS_ROWID package

More Related Content

What's hot

Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Abdul Rehman
 
MS Sql Server: Manipulating Database
MS Sql Server: Manipulating DatabaseMS Sql Server: Manipulating Database
MS Sql Server: Manipulating DatabaseDataminingTools Inc
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHEREI L0V3 CODING DR
 
Spot db consistency checking and optimization in spatial database
Spot db  consistency checking and optimization in spatial databaseSpot db  consistency checking and optimization in spatial database
Spot db consistency checking and optimization in spatial databasePratik Udapure
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & PreparationAminaRepo
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL Rc Os
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statementsVivek Singh
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table1keydata
 

What's hot (14)

1 ddl
1 ddl1 ddl
1 ddl
 
Stata tutorial university of princeton
Stata tutorial university of princetonStata tutorial university of princeton
Stata tutorial university of princeton
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
MS Sql Server: Manipulating Database
MS Sql Server: Manipulating DatabaseMS Sql Server: Manipulating Database
MS Sql Server: Manipulating Database
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERE
 
Spot db consistency checking and optimization in spatial database
Spot db  consistency checking and optimization in spatial databaseSpot db  consistency checking and optimization in spatial database
Spot db consistency checking and optimization in spatial database
 
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation:  Data Files, and Data Cleaning & PreparationAaa ped-6-Data manipulation:  Data Files, and Data Cleaning & Preparation
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
 
Apache HBase
Apache HBase  Apache HBase
Apache HBase
 
COMPUTERS SQL
COMPUTERS SQL COMPUTERS SQL
COMPUTERS SQL
 
Sql delete, truncate, drop statements
Sql delete, truncate, drop statementsSql delete, truncate, drop statements
Sql delete, truncate, drop statements
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
SQL
SQLSQL
SQL
 

Similar to Clase 11 manejo tablas modificada

database-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptdatabase-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptIftikhar70
 
database-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptdatabase-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptsubbu998029
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10Umair Amjad
 
Data warehousing in the era of Big Data: Deep Dive into Amazon Redshift
Data warehousing in the era of Big Data: Deep Dive into Amazon RedshiftData warehousing in the era of Big Data: Deep Dive into Amazon Redshift
Data warehousing in the era of Big Data: Deep Dive into Amazon RedshiftAmazon Web Services
 
Hive and HiveQL - Module6
Hive and HiveQL - Module6Hive and HiveQL - Module6
Hive and HiveQL - Module6Rohit Agrawal
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSwapnilSaurav7
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Web Services
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
IBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slidesenosislearningcom
 

Similar to Clase 11 manejo tablas modificada (20)

Database
Database Database
Database
 
database-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptdatabase-stucture-and-space-managment.ppt
database-stucture-and-space-managment.ppt
 
database-stucture-and-space-managment.ppt
database-stucture-and-space-managment.pptdatabase-stucture-and-space-managment.ppt
database-stucture-and-space-managment.ppt
 
SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10SQL WORKSHOP::Lecture 10
SQL WORKSHOP::Lecture 10
 
Data warehousing in the era of Big Data: Deep Dive into Amazon Redshift
Data warehousing in the era of Big Data: Deep Dive into Amazon RedshiftData warehousing in the era of Big Data: Deep Dive into Amazon Redshift
Data warehousing in the era of Big Data: Deep Dive into Amazon Redshift
 
Unit - II.pptx
Unit - II.pptxUnit - II.pptx
Unit - II.pptx
 
Hive and HiveQL - Module6
Hive and HiveQL - Module6Hive and HiveQL - Module6
Hive and HiveQL - Module6
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
Deep Dive on Amazon Redshift
Deep Dive on Amazon RedshiftDeep Dive on Amazon Redshift
Deep Dive on Amazon Redshift
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and Optimization
 
Database Sizing
Database SizingDatabase Sizing
Database Sizing
 
MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
IBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration BasicsIBM DB2 for z/OS Administration Basics
IBM DB2 for z/OS Administration Basics
 
SQL SERVER Training in Pune Slides
SQL SERVER Training in Pune SlidesSQL SERVER Training in Pune Slides
SQL SERVER Training in Pune Slides
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 

More from Titiushko Jazz

Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)
Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)
Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)Titiushko Jazz
 
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)Titiushko Jazz
 
Unidad vii esp parte 2 introduccion a data warehouse y datamining
Unidad vii esp parte 2 introduccion a data warehouse y dataminingUnidad vii esp parte 2 introduccion a data warehouse y datamining
Unidad vii esp parte 2 introduccion a data warehouse y dataminingTitiushko Jazz
 
Unidad vi esp parte 2 procesimientos en plsql y transact sql
Unidad vi esp parte 2 procesimientos en plsql y transact sqlUnidad vi esp parte 2 procesimientos en plsql y transact sql
Unidad vi esp parte 2 procesimientos en plsql y transact sqlTitiushko Jazz
 
Tarea pronosticos eily
Tarea pronosticos eilyTarea pronosticos eily
Tarea pronosticos eilyTitiushko Jazz
 
Proyecto teórico práctico
Proyecto teórico prácticoProyecto teórico práctico
Proyecto teórico prácticoTitiushko Jazz
 

More from Titiushko Jazz (20)

Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)
Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)
Unidad vii esp parte 3 clase de inteligencia de negocios (datawarehouse)
 
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)
Unidad vii esp parte 3 clase de datawarehouse ( ing. doño)
 
Unidad vii esp parte 2 introduccion a data warehouse y datamining
Unidad vii esp parte 2 introduccion a data warehouse y dataminingUnidad vii esp parte 2 introduccion a data warehouse y datamining
Unidad vii esp parte 2 introduccion a data warehouse y datamining
 
Unidad vi esp parte 2 procesimientos en plsql y transact sql
Unidad vi esp parte 2 procesimientos en plsql y transact sqlUnidad vi esp parte 2 procesimientos en plsql y transact sql
Unidad vi esp parte 2 procesimientos en plsql y transact sql
 
Unidad ii esp parte 2
Unidad ii esp parte 2Unidad ii esp parte 2
Unidad ii esp parte 2
 
Unidad ii esp parte 1
Unidad ii esp parte 1Unidad ii esp parte 1
Unidad ii esp parte 1
 
Unidad i esp parte 2
Unidad i esp parte 2Unidad i esp parte 2
Unidad i esp parte 2
 
Unidad i esp parte 1
Unidad i esp parte 1Unidad i esp parte 1
Unidad i esp parte 1
 
Tarea pronosticos eily
Tarea pronosticos eilyTarea pronosticos eily
Tarea pronosticos eily
 
Sociedades limitadas
Sociedades limitadasSociedades limitadas
Sociedades limitadas
 
Rhu
RhuRhu
Rhu
 
Qué es un proyecto
Qué es un proyectoQué es un proyecto
Qué es un proyecto
 
Proyecto teórico práctico
Proyecto teórico prácticoProyecto teórico práctico
Proyecto teórico práctico
 
Presentacion1630
Presentacion1630Presentacion1630
Presentacion1630
 
Presentacion1410
Presentacion1410Presentacion1410
Presentacion1410
 
Presentacion1310
Presentacion1310Presentacion1310
Presentacion1310
 
Presentacion1210
Presentacion1210Presentacion1210
Presentacion1210
 
Presentacion1220
Presentacion1220Presentacion1220
Presentacion1220
 
Presentacion1001
Presentacion1001Presentacion1001
Presentacion1001
 
Presentacion810
Presentacion810Presentacion810
Presentacion810
 

Clase 11 manejo tablas modificada