CREATE TABLE EMPLOYEE
(
EMPNO INT NOT NULL,
LASTNAME VARCHAR(20) NOT NULL,
...,
PRIMARY KEY (EMPNO, LASTNAME)
)
注意:在数据库中, 每条记录的物理存储是无序的。
如果没有索引,将会搜索整个表
Create an Index:
The physical storage of rows in a base table is not ordered. When a row is inserted, it is placed in the most convenient storage location that can accommodate it. When searching for rows of a table that meet a particular selection condition and the table has no indexes, the entire table is scanned. An index optimizes data retrieval without performing a lengthy sequential search. The following SQL statement creates a
non-unique index called LNAME from the LASTNAME column on the EMPLOYEE table, sorted in ascending(升序) order:
CREATE INDEX LNAME ON EMPLOYEE (LASTNAME ASC)
The following SQL statement creates a unique index on the phone number column:
CREATE UNIQUE INDEX PH ON EMPLOYEE (PHONENO DESC)
参考:http://users.sdsc.edu/~jrowley/db2/howto.html