Обсуждение: Modifying existing tables

Поиск
Список
Период
Сортировка

Modifying existing tables

От
Steve Doerr
Дата:
Is this the only way to add attributes to an existing table, and add
unique and a default(for example) to existing attributes?

Just wondered if there are alternatives.  I didn't really see this in
the docs or mailing lists.

Thanks for any input.
Steve

original table:
CREATE TABLE table (
    attrib1 int,
    attrib2 int,
);


table edit:
CREATE TABLE newtable (
    attrib1 int UNIQUE,
    attrib2 int DEFAULT 1,
    attrib3 int
);

INSERT INTO newtable (attrib1, attrib2)
SELECT attrib1, attrib2 FROM table;

DROP TABLE table;
ALTER TABLE newtable RENAME TO table;