Re: Adding Serial Type

Поиск
Список
Период
Сортировка
От John DeSoi
Тема Re: Adding Serial Type
Дата
Msg-id 183b3bdba4539903b1a778f815f6aa43@pgedit.com
обсуждение исходный текст
Ответ на Adding Serial Type  (David Pratt <fairwinds@eastlink.ca>)
Список pgsql-admin
On May 28, 2005, at 1:27 PM, David Pratt wrote:

> CREATE TABLE new_table (
>     id                             SERIAL UNIQUE NOT NULL,
>     description             TEXT NOT NULL
> );
>
> Or should I just use below because Serial type implies this.
>
> CREATE TABLE new_table (
>     id                             SERIAL,
>     description             TEXT NOT NULL
> );


The first one because it is possible for the serial to wrap around or
some other bad thing could happen if the serial is accidently reset.

But if id is really the primary key, then I would use SERIAL PRIMARY
KEY which implies UNIQUE NOT NULL. From the CREATE TABLE documentation:

The primary key constraint specifies that a column or columns of a
table  may contain only unique (non-duplicate), nonnull values.
Technically, PRIMARY KEY is merely a  combination of UNIQUE and NOT
NULL, but  identifying a set of columns as primary key also provides
metadata about the design of the schema, as a primary key  implies that
other tables  may rely on this set of columns as a unique identifier
for rows.


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


В списке pgsql-admin по дате отправления:

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: Adding Serial Type
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Adding Serial Type