Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / Database concepts.pdf
Скачиваний:
29
Добавлен:
12.05.2015
Размер:
6.96 Mб
Скачать

Tables

LONG, then Oracle always stores this column last. Also, if a table is altered so that a new column is added, then the new column becomes the last column stored.

In general, try to place columns that frequently contain nulls last so that rows take less space. Note, though, that if the table you are creating includes a LONG column as well, then the benefits of placing frequently null columns last are lost.

Nulls Indicate Absence of Value

A null is the absence of a value in a column of a row. Nulls indicate missing, unknown, or inapplicable data. A null should not be used to imply any other value, such as zero. A column allows nulls unless a NOT NULL or PRIMARY KEY integrity constraint has been defined for the column, in which case no row can be inserted without a value for that column.

Nulls are stored in the database if they fall between columns with data values. In these cases they require 1 byte to store the length of the column (zero).

Trailing nulls in a row require no storage because a new row header signals that the remaining columns in the previous row are null. For example, if the last three columns of a table are null, no information is stored for those columns. In tables with many columns, the columns more likely to contain nulls should be defined last to conserve disk space.

Most comparisons between nulls and other values are by definition neither true nor false, but unknown. To identify nulls in SQL, use the IS NULL predicate. Use the SQL function NVL to convert nulls to non-null values.

Nulls are not indexed, except when the cluster key column value is null or the index is a bitmap index.

See Also:

Oracle9i SQL Reference for more information about comparisons using IS NULL and the NVL function

"Indexes and Nulls" on page 10-31

"Bitmap Indexes and Nulls" on page 10-52

Default Values for Columns

You can assign a default value to a column of a table so that when a new row is inserted and a value for the column is omitted or keyword DEFAULT is supplied, a default value is supplied automatically. Default column values work as though an INSERT statement actually specifies the default value.

10-10 Oracle9i Database Concepts

Tables

The datatype of the default literal or expression must match or be convertible to the column datatype.

If a default value is not explicitly defined for a column, then the default for the column is implicitly set to NULL.

Default Value Insertion and Integrity Constraint Checking

Integrity constraint checking occurs after the row with a default value is inserted. For example, in Figure 10–4, a row is inserted into the emp table that does not include a value for the employee’s department number. Because no value is supplied for the department number, Oracle inserts the deptno column’s default value of 20. After inserting the default value, Oracle checks the FOREIGN KEY integrity constraint defined on the deptno column.

See Also: Chapter 21, "Data Integrity" for more information about integrity constraints

Schema Objects 10-11

Tables

Figure 10–4 DEFAULT Column Values

Parent Key

Table DEPT

 

DEPTNO

DNAME

LOC

20

RESEARCH

DALLAS

30

SALES

CHICAGO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Foreign Key

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Table EMP

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

EMPNO

 

ENAME

 

JOB

 

MGR

 

HIREDATE

 

SAL

 

COMM

 

DEPTNO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7329

 

SMITH

 

CEO

 

 

 

17–DEC–85

 

9000.00

 

 

 

20

 

 

 

 

 

7499

 

ALLEN

 

VP_SALES

 

7329

 

20–FEB–90

 

7500.00

 

100.00

 

30

 

 

 

 

 

7521

 

WARD

 

MANAGER

 

7499

 

22–FEB–90

 

5000.00

 

200.00

 

30

 

 

 

 

 

7566

 

JONES

 

SALESMAN

 

7521

 

02–APR–90

 

2975.00

 

400.00

 

30

 

 

 

 

 

7691

 

OSTER

 

SALESMAN

 

7521

 

06–APR–90

 

2975.00

 

400.00

 

20

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

New row to be inserted, without value

INSERT

for DEPTNO column.

INTO

 

 

Default Value

(if no value is given for this column, the default of 20 is used)

7691

OSTER

SALESMAN 7521

06–APR–90 2975.00

400.00

Partitioned Tables

Partitioned tables allow your data to be broken down into smaller, more manageable pieces called partitions, or even subpartitions. Indexes can be partitioned in similar fashion. Each partition can be managed individually, and can operate independently of the other partitions, thus providing a structure that can be better tuned for availability and performance.

See Also: Chapter 11, "Partitioned Tables and Indexes"

10-12 Oracle9i Database Concepts

Tables

Nested Tables

You can create a table with a column whose datatype is another table. That is, tables can be nested within other tables as values in a column. The Oracle server stores nested table data out of line from the rows of the parent table, using a store table that is associated with the nested table column. The parent row contains a unique set identifier value associated with a nested table instance.

See Also:

"Nested Tables Description" on page 13-12

Oracle9i Application Developer’s Guide - Fundamentals

Temporary Tables

In addition to permanent tables, Oracle can create temporary tables to hold session-private data that exists only for the duration of a transaction or session.

The CREATE GLOBAL TEMPORARY TABLE statement creates a temporary table that can be transaction-specific or session-specific. For transaction-specific temporary tables, data exists for the duration of the transaction. For session-specific temporary tables, data exists for the duration of the session. Data in a temporary table is private to the session. Each session can only see and modify its own data. DML locks are not acquired on the data of the temporary tables. The LOCK statement has no effect on a temporary table, because each session has its own private data.

A TRUNCATE statement issued on a session-specific temporary table truncates data in its own session. It does not truncate the data of other sessions that are using the same table.

DML statements on temporary tables do not generate redo logs for the data changes. However, undo logs for the data and redo logs for the undo logs are generated. Data from the temporary table is automatically dropped in the case of session termination, either when the user logs off or when the session terminates abnormally such as during a session or instance failure.

You can create indexes for temporary tables using the CREATE INDEX statement. Indexes created on temporary tables are also temporary, and the data in the index has the same session or transaction scope as the data in the temporary table.

You can create views that access both temporary and permanent tables. You can also create triggers on temporary tables.

The Export and Import utilities can export and import the definition of a temporary table. However, no data rows are exported even if you use the ROWS clause.

Schema Objects 10-13

Соседние файлы в папке Oracle selected docs