Shehroz
Shehroz

Reputation: 447

How to add same column to multiple tables in a DB and fill it with a constant value?

I have a database with multiple tables. I want to add a new column to each one of them and fill these column with some constant integer value. My search on google did not give me desired answer.

I am using PostgreSQL and PHP.

Upvotes: 0

Views: 467

Answers (1)

Tom
Tom

Reputation: 3331

Can't you use ALTER TABLE to create a new column and SET DEFAULT to set the default value to all column fields?

Like:

ALTER TABLE mytable ADD COLUMN mynumber integer; ALTER mynumber SET DEFAULT 7

(http://www.postgresql.org/docs/8.2/static/sql-altertable.html)

Upvotes: 2

Related Questions