[英]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. 我正在使用PostgreSQL和PHP。
Can't you use ALTER TABLE to create a new column and SET DEFAULT to set the default value to all column fields? 您不能使用ALTER TABLE创建新列,并使用SET DEFAULT将默认值设置为所有列字段吗?
Like: 喜欢:
ALTER TABLE mytable ADD COLUMN mynumber integer; ALTER TABLE mytable ADD COLUMN mynumber integer; ALTER mynumber SET DEFAULT 7
更改mynumber SET DEFAULT 7
(http://www.postgresql.org/docs/8.2/static/sql-altertable.html) (http://www.postgresql.org/docs/8.2/static/sql-altertable.html)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.