Use the Primary Key Clause of Create Table. (You can use a Create Index statement to create additional indexes)
CREATE [ TEMPORARY | TEMP ] TABLE table (
column type
[ NULL | NOT NULL ] [ UNIQUE ] [ DEFAULT value ]
[column_constraint_clause | PRIMARY KEY } [ ... ] ]
[, ... ]
[, PRIMARY KEY ( column [, ...] ) ]
[, CHECK ( condition ) ]
[, table_constraint_clause ]
) [ INHERITS ( inherited_table [, ...] ) ]
PRIMARY KEY Constraint
[ CONSTRAINT name ] PRIMARY KEY
Inputs
CONSTRAINT name
An arbitrary name for the constraint.
Outputs
ERROR: Cannot insert a duplicate key into a unique index.
This occurs at run-time if one tries to insert a duplicate value into a column subject to a PRIMARY KEY constraint.
Description
The PRIMARY KEY column constraint specifies that a column of a table may contain only unique (non-duplicate), non-NULL values. The definition of the specified column does not have to
include an explicit NOT NULL constraint to be included in a PRIMARY KEY constraint.
Only one PRIMARY KEY can be specified for a table.
Notes
Postgres automatically creates a unique index to assure data integrity. (See CREATE INDEX statement)
The PRIMARY KEY constraint should name a set of columns that is different from other sets of columns named by any UNIQUE constraint defined for the same table, since it will result in
duplication of equivalent indexes and unproductive additional runtime overhead. However, Postgres does not specifically disallow this.
John L. Pierce wrote:
Hello, I have tried to create an index inside of a create table statement, and I receive an error message.
Is it possible to do this, or must the indices be created in a seperate create statement.
TIA
John