Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oracle9i Database Administrator: Implementation and Administration 1 Chapter 7 Basic Table Management.

Similar presentations


Presentation on theme: "Oracle9i Database Administrator: Implementation and Administration 1 Chapter 7 Basic Table Management."— Presentation transcript:

1 Oracle9i Database Administrator: Implementation and Administration 1 Chapter 7 Basic Table Management

2 Oracle9i Database Administrator: Implementation and Administration 2 Objectives  Describe the different types of tables and their storage methods  Create relational and temporary tables  Create tables containing varrays and nested tables  Create object and partitioned tables

3 Oracle9i Database Administrator: Implementation and Administration 3 Introduction to Table Structures Table types:  Relational  Index-organized  Object  Temporary  External  Nested  XML  Cluster

4 Oracle9i Database Administrator: Implementation and Administration 4 Setting Block Space Usage Syntax of the CREATE TABLE command: CREATE TABLE ( ) TABLESPACE STORAGE ( ) Area of focus in this chapter

5 Oracle9i Database Administrator: Implementation and Administration 5 Setting Block Space Usage Expanded STORAGE clause syntax: TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MINEXTENTS MAXEXTENTS FREELISTS FREELIST GROUPS BUFFER_POOL KEEP|RECYCLE|DEFAULT) PCTFREE PCTUSED INITRANS MAXTRANS INITIAL: Size of the first extent NEXT: Size of next and all subsequent extents PCTINCREASE: Range of 0 to 100 Percent of previous extent to increase each subsequent extent

6 Oracle9i Database Administrator: Implementation and Administration 6 Setting Block Space Usage Expanded STORAGE clause syntax: TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MINEXTENTS MAXEXTENTS FREELISTS FREELIST GROUPS BUFFER_POOL KEEP|RECYCLE|DEFAULT) PCTFREE PCTUSED INITRANS MAXTRANS MINEXTENTS: Min. number of extents MAXEXTENTS: Max. number of extents Primarily for Real Application Clusters FREELISTS: Number of freelists per extent FREELIST GROUPS: Number of freelist groups per extent

7 Oracle9i Database Administrator: Implementation and Administration 7 Setting Block Space Usage Expanded STORAGE clause syntax: TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MINEXTENTS MAXEXTENTS FREELISTS FREELIST GROUPS BUFFER_POOL KEEP|RECYCLE|DEFAULT) PCTFREE PCTUSED INITRANS MAXTRANS BUFFER POOL: buffer area in which data blocks from the table are stored in the SGA PCTFREE: Minimum percent of data block reserved for updates PCTUSED: Percent of data block used below which block is re-opened for updates

8 Oracle9i Database Administrator: Implementation and Administration 8 Setting Block Space Usage Expanded STORAGE clause syntax: TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MINEXTENTS MAXEXTENTS FREELISTS FREELIST GROUPS BUFFER_POOL KEEP|RECYCLE|DEFAULT) PCTFREE PCTUSED INITRANS MAXTRANS Initial and maximum number of transactions that can concurrently access a data block

9 Oracle9i Database Administrator: Implementation and Administration 9 Setting Block Space Usage Data block components Arrows indicate direction of growth

10 Oracle9i Database Administrator: Implementation and Administration 10 Setting Block Space Usage Overhead: Grows when more rows are inserted Grows when INITRANS or MAXTRANS are increased Never shrinks

11 Oracle9i Database Administrator: Implementation and Administration 11 Setting Block Space Usage Free space: Cannot insert rows if free space exceeds PCTFREE Cannot update rows if no free space left Can resume inserting rows if used space falls below PCTUSED

12 Oracle9i Database Administrator: Implementation and Administration 12 Setting Block Space Usage Row data: Grows when rows are inserted or updated Shrinks when rows are deleted or updated

13 Oracle9i Database Administrator: Implementation and Administration 13 Setting Block Space Usage When a single row spans two data blocks: Chained row Migrated row

14 Oracle9i Database Administrator: Implementation and Administration 14 Storage Methods Options when setting storage for a table:  Use tablespace defaults  Customize the STORAGE clause for each table  Use Oracle defaults

15 Oracle9i Database Administrator: Implementation and Administration 15 Storage Methods: How to Set Storage For Locally Managed Tables Simplified syntax: TABLESPACE STORAGE (INITIAL )  Example : CREATE TABLE CH07BICYCLE (BIKE_ID NUMBER(10) PRIMARY KEY, BIKE_MAKER VARCHAR2(50) NOT NULL, STYLE VARCHAR2(15)) TABLESPACE USERS STORAGE (INITIAL 25M);

16 Oracle9i Database Administrator: Implementation and Administration 16 Storage Methods: How to Set Storage For Dictionary-Managed Tables Example (customize storage for table) : CREATE TABLE TRUCK_MAINTENANCE (TRUCK_ID NUMBER(10), REPAIR_DATE DATE, PROBLEM_DESCRIPTION VARCHAR2(2000), DIAGNOSIS VARCHAR2(2000), BILLING_DATE DATE, BILLING_AMT NUMBER (10,2)) TABLESPACE USER_DTAB STORAGE (INITIAL 80M NEXT 40M PCT INCREASE 0 MINEXTENTS 2 MAXEXTENTS 25) PCTFREE 25 PCTUSED 50 MINTRANS 1 MAXTRANS 2;

17 Oracle9i Database Administrator: Implementation and Administration 17 Storage Methods: How to Set Storage For Dictionary-Managed Tables Example (use tablespace defaults) : CREATE TABLE BIKE_MAINTENANCE (BIKE_ID NUMBER(10), REPAIR_DATE DATE, DESCRIPTION VARCHAR2(30));

18 Oracle9i Database Administrator: Implementation and Administration 18 Row Structure and the ROWID Row components: Row header Column Data

19 Oracle9i Database Administrator: Implementation and Administration 19 Row Structure and the ROWID Physical rowid: Used for most tables Never changes once the row is created Subtypes: Extended: Default Restricted: Old format Logical rowid: Identifies row by primary key value Used for index-organized tables

20 Oracle9i Database Administrator: Implementation and Administration 20 Row Structure and the ROWID Internal format of each rowid type

21 Oracle9i Database Administrator: Implementation and Administration 21 Creating Tables Expanded syntax: CREATE TABLE. ( NULL|NOT NULL DEFAULT CHECK,... ) TABLESPACE STORAGE (INITIAL NEXT PCTINCREASE MINEXTENTS MAXEXTENTS FREELISTS FREELIST GROUPS BUFFER_POOL KEEP|RECYCLE|DEFAULT) PCTFREE PCTUSED INITRANS MAXTRANS

22 Oracle9i Database Administrator: Implementation and Administration 22 Creating Tables: Columns and Data Types Datatypes: Character types: CHAR, VARCHAR, VARCHAR2 NCHAR, NVARCHAR, NVARCHAR2 LONG Number type: NUMBER

23 Oracle9i Database Administrator: Implementation and Administration 23 Creating Tables: Columns and Data Types Datatypes: Date and time types: DATE, TIMESTAMP TIMESTAMP WITH TIME ZONE TIMESTAMP WITH LOCAL TIME ZONE INTERVAL YEAR TO MONTH INTERVAL DAY TO SECOND LOB BLOB, CLOB, NCLOB, BFILE New in Oracle9i

24 Oracle9i Database Administrator: Implementation and Administration 24 Creating Tables: Columns and Data Types Raw: RAW, LONG RAW Rowid: ROWID, UROWID Collection: VARRAY NESTED TABLE Object data types: REF User-defined data type

25 Oracle9i Database Administrator: Implementation and Administration 25 Creating Relational Tables Factors in relational table design: Name of the table Name and data type of all columns Estimated initial size and growth pattern Location of the table Constraints, relationships to other tables, default data

26 Oracle9i Database Administrator: Implementation and Administration 26 Creating Relational Tables Example: CREATE TABLE EMPLOYEE (EMPLOYEE_ID NUMBER (10), JOB_TITLE VARCHAR2(45), first_name varchar2(40), Last_name varchar2(40), phone_number Varchar2(20)); Storage settings used: TABLESPACE: User's default tablespace SYSTEM, if no user default Each STORAGE setting: The tablespace's default storage setting Oracle default, if no tablespace default setting

27 Oracle9i Database Administrator: Implementation and Administration 27 Creating Temporary Tables Example: CREATE GLOBAL TEMPORARY TABLE EDITOR_REVENUE ON COMMIT PRESERVE ROWS AS SELECT E.FIRST_NAME || ' ' || E.LAST_NAME EDITOR, SUM(CA.PRICE) ANNUAL_REVENUE FROM CLASSIFIED_AD CA JOIN EMPLOYEE E ON (CA.INTAKE_EDITOR_ID = E.EMPLOYEE_ID) WHERE TO_CHAR(CA.PLACED_DATE, 'YYYY') = '2003' GROUP BY FIRST_NAME || ' ' || LAST_NAME; Alternative: ON COMMIT DELETE ROWS

28 Oracle9i Database Administrator: Implementation and Administration 28 Creating Varrays and Nested Tables

29 Oracle9i Database Administrator: Implementation and Administration 29 Creating Varrays and Nested Tables Example of nested table: CREATE TABLE CLASSIFIED_SECTION (SECTION_NO NUMBER NOT NULL, SECTION_TITLE VARCHAR2(50), BASE_RATE_PER_WORD NUMBER(4,3), CONTACT_EDITOR CLASSMATE.CONTACT_TABLE) NESTED TABLE CONTACT_EDITOR STORE AS NESTED_EDITORS; Nested table data stored in out of line table User-defined table type

30 Oracle9i Database Administrator: Implementation and Administration 30 Creating Varrays and Nested Tables Varrays: Contain finite lists of data Are stored inside the table

31 Oracle9i Database Administrator: Implementation and Administration 31 Creating Varrays and Nested Tables Nested tables: Contain unlimited rows of data Are stored out of line from the table

32 Oracle9i Database Administrator: Implementation and Administration 32 Creating Object Tables Same storage settings as relational tables Example: CREATE TABLE CUSTOMER_ADDRESS OF CUSTOMER_ADDRESS_TYPE; Object type datatype

33 Oracle9i Database Administrator: Implementation and Administration 33 Creating Partitioned Tables Allows one table to span multiple tablespaces Intended for very large tables Each partition can have its own storage settings Types of partitions:  Range  Hash  List  Composite range-hash  Composite range-list

34 Oracle9i Database Administrator: Implementation and Administration 34 Range Partitioning Designate a range of values Specify one or multiple columns Example: CREATE TABLE TRANSACTION_RECORD ( ACCT_NO NUMBER NOT NULL, …) PARTITION BY RANGE (ACCT_NO) ( PARTITION TRANS_P1 VALUES LESS THAN (2900999) TABLESPACE TBS1, PARTITION TRANS_P2 VALUES LESS THAN (5900999) TABLESPACE USER_DATA, PARTITION TRANS_P3 VALUES LESS THAN (9900999) TABLESPACE USER_ALT); Partition key Range Storage

35 Oracle9i Database Administrator: Implementation and Administration 35 Hash Partitioning Supplies an even distribution to data rows to spread the I/O load across devices Specify one or multiple columns Example: CREATE TABLE MORTGAGE_HISTORY (LOAN_NO NUMBER, ACCT_NO NUMBER, DATE_CREATED DATE, MORTGAGE_AMOUNT NUMBER) PARTITION BY HASH (DATE_CREATED) PARTITIONS 3 STORE IN (HISTORY_TBSP1, HISTORY2, HISTORYEXTENDED); Partition key Number of partitions Storage

36 Oracle9i Database Administrator: Implementation and Administration 36 List Partitioning Similar to range, but specify exact values instead of ranges Can use only one column Example: CREATE TABLE TRANS_BY_BRANCH_HISTORY (BRANCH_ID NUMBER(9,0), BRANCH_REGION VARCHAR2(10), …) PARTITION BY LIST (BRANCH_REGION) (PARTITION WESTERN VALUES ('WESTCOAST', 'NORTHWEST') TABLESPACE HIST3, PARTITION MOUNTAIN VALUES ('ROCKIES', 'SOUTHWEST') TABLESPACE HIST3, PARTITION MIDWEST VALUES ('MIDWEST', 'IL-METRO') STORAGE (INITIAL 20M NEXT 40M PCTINCREASE 20) TABLESPACE HIST1; Storage Partition key List values

37 Oracle9i Database Administrator: Implementation and Administration 37 Composite Range-hash Partitioning Partition by range Sub-partition each partition by hash values Example: CREATE TABLE TRANSACTION_RECORD ( ACCT_NO NUMBER NOT NULL, ACTION VARCHAR2(5) NOT NULL, AMOUNT NUMBER(8,2) NOT NULL, SENDING_ACCT_NO NUMBER NOT NULL, ACTION_DATE DATE NOT NULL ) PARTITION BY RANGE (ACCT_NO) SUBPARTITION BY HASH (ACTION_DATE) SUBPARTITIONS 8 STORE IN (TBS1, USER_DATA, USER_ALT, USER_ALT2) PARTITION TRANS_P1 VALUES LESS THAN (2900999), PARTITION TRANS_P2 VALUES LESS THAN (5900999), PARTITION TRANS_P3 VALUES LESS THAN (9900999)); Storage Partition key Sub-partition key Number of Sub-part. Range values

38 Oracle9i Database Administrator: Implementation and Administration 38 Composite Range-list Partitioning Partition by range Sub-partition each partition by list of values Example: CREATE TABLE TRANSACTION_RECORD ( ACCT_NO NUMBER NOT NULL, ACTION …) PARTITION BY RANGE (ACCT_NO) SUBPARTITION BY LIST (ACTION) SUBPARTITION TEMPLATE (SUBPARTITION WESTERN VALUES ('WESTCOAST', 'NORTHWEST'), SUBPARTITION MOUNTAIN VALUES ('ROCKIES', 'SOUTHWEST')) (PARTITION TRANS_P1 VALUES LESS THAN (9900999) TABLESPACE HIST3, PARTITION TRANS_P2 VALUES LESS THAN (5900999) TABLESPACE HIST2); Storage Partition key Sub-partition key Sub-part. template Sub-part. list values Range values

39 Oracle9i Database Administrator: Implementation and Administration 39 Chapter Summary Relational tables reside in a single segment within a single tablespace, unless the table is partitioned A temporary table, which is seen only by one user, is created for private data Tables can use the default storage settings of the tablespace or use their own settings Chained rows and migrated rows slow down performance speed

40 Oracle9i Database Administrator: Implementation and Administration 40 Chapter Summary A row is made up of a row header and column data A rowid can be physical or logical Relational tables can be defined as a list of columns or as a subquery Varrays and nested tables are like tables within one column of another table

41 Oracle9i Database Administrator: Implementation and Administration 41 Chapter Summary Nested table data is stored out of line (in a separate location) from the primary table A partition of a table resides in its own segment Partitioning can be done with range, list, hash, or composite methods


Download ppt "Oracle9i Database Administrator: Implementation and Administration 1 Chapter 7 Basic Table Management."

Similar presentations


Ads by Google