Friday, August 25, 2006
Tables
Tables :
| Regular Tables | : | The default table. Rows can be stored in any matter depending upon the activity in the database. |
| Partitioned Tables
| : | These enable the building of scalable applications. Characteristics:
|
| Index Organized Tables
| : | It is like a heap table with primary key on one or more of its columns. However instead of maintaining two separate storages, an IOT maintains a single B-tree containing the primary key and the rest of the column values. An overflow segment may exist due to PCTTHRESHOLD value being set and the result of longer row lengths requiring the overflow area. Characteristics:
|
| Clustered Tables | : | A cluster is made up of a table or group of table that share the same data blocks, which are grouped together because they share common columns and are often used together. Characteristics:
|
|
Note : Display uses base-64 encoding scheme using following character sets : A-Z,a-z,0-9, and /. That is a total 64 characters. |
Locating a row using rowid
| Segment no.(Data object No.) | Points to tablespace > | Tablespace (since a segment can reside in only one tablespace) |
|
| Relative file no. > | Relative Datafile of the tablespace |
|
| Block no. > | Block No. |
|
| Row ID . > | Row directory entry for the row |
|
| Row > | Beginning of the row |
Restricted ROWID Format in Oracle 7 & earlier : break up of 6 bytes:
|
Notes :
Uses :
|
|
Notes :
|
| CREATE TABLE tablename (column_name, column_datatype ,.....) |
---|---|
| Note : The above is a subset of the CREATE TABLE clause. |
| INITIAL | : |
|
---|---|---|---|
| NEXT | : |
|
| PCTINCREASE | : |
|
| MINEXTENT | : |
|
| MAXEXTENT | : |
|
| PCTFREE | : |
|
| PCTUSED | : | Deprecated from Oracle 9i together with FREELIST, FREELIST GROUPS |
| INTRANS | : |
|
| MAXTRANS | : |
|
| TABLESPACE | : |
|
Changing Storage & Block Utilization parameters:
| Syntax | Example |
| ALTER TABLE table_name | ALTER TABLE hr.employees |
| PCTINCREASE | : | PCTINCREASE will be registered in the data dictionary. It will be used to calculate NEXT, when next extent is allocated. |
| MINEXTENT | : | Can be changed to any value <= to the current no. of extents. Is has no immediate effect but will be used if the table is TRUNCATED. |
| MAXEXTENT | : | Can be changed to any value >= to the current no. of extents. It can also be set to UNLIMITED. |
| Restrictions:
|
|
|
Creating Temporary Tables :
| CREATE GLOBAL TEMPORARY TABLE tablename Note:
|
---|
| ON COMMIT DELETE ROWS | : | Rows only visible within transaction. |
---|---|---|---|
| ON COMMIT PRESERVE ROWS | : | Rows visible during entire session. |
Setting PCTFREE and PCTUSED:
| PCTFREE | : | Average increase in row_size *100 Average row Size | i.e. The free space should be able to accommodate average row size increases |
| Note: Higher PCTFREE is used to accommodate updates within a database block. Higher PCTFREE results in lower block density- fewer rows per block. Use higher value for:
|
| PCTUSED | : | 100 – PCTFREE - Average row size | i.e. Whenever there is space to accommodate a single new row. |
| Note: Set so that the block is returned to the free list only when there is sufficient space to accommodate an average row. If it does not, then Oracle Server looks up the 2nd block on the free list. This linear scan continues until a block with sufficient space is found or the end of list is reached. The value of average row can be found using ANALYZE TABLE command. |
Row Migration & Chaining:
| Row Migration | : | When PCTFREE is low, there may not be sufficient space in the block to accommodate a row growth due to update. In such a situation Oracle server moves the entire row to a new block & leaves a pointer from the original block to the new location. This causes decrease in I/O performance associated with this row due to two data block scans. |
| Chaining | : | Row chaining occurs when a row is too large to fit into any block. Oracle server divides the row into smaller chunks called row pieces. Each row piece is stored in a block along with necessary pointers to retrieve and assemble the entire row. Row chaining can be minimised by choosing a higher block size, or by splitting a table into multiple tables with fewer columns. |
Manually Allocating Extents:
| Syntax | Example |
| ALTER TABLE [schema.] tablename | ALTER TABLE hr.employees |
| Purpose:
Notes:
|
Nonpartitioned Table Reorganization:
| ALTER TABLE hr.employees |
|
| Using this command a non-partitioned table can be moved without using EXPORT or IMPORT utilility. In addition, storage parameters can be changed too. Purpose:
Note: Moving the tables requires rebuilding of indexed otherwise 'index in unusable state' error is thrown. |
Truncating a Table:
| Syntax: | Example: |
| TRUNCATE TABLE [schema.] tablename | TRUNCATE TABLE hr.employees; |
| Characteristics:
|
| Syntax: | Example: |
| DROP TABLE [schema.] tablename | DROP TABLE hr.departments |
| Characteristics:
|
| ALTER TABLE hr.employees |
| Characteristics:
|
UNUSED column option:
| ALTER TABLE hr.employees
ALTER TABLE hr.employees ALTER TABLE hr.employees |
| Characteristics:
Restrictions on dropping a Column. Can't do the followings:
|
Views
| DBA_UNUSED_COL_TABS |
|
| DBA_PARTIAL_DROP_TABS |
|
| DBA_TABLES |
|
| DBA_OBJECTS |
|