ALTER TABLE,在非空列中设置空值,PostgreSQL 9.1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13643806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ALTER TABLE, set null in not null column, PostgreSQL 9.1
提问by Brian Brown
I have a table with not null column, How to set a null value in this column as default?
我有一个非空列的表,如何将此列中的空值设置为默认值?
I mean, I want to do something like this:
我的意思是,我想做这样的事情:
postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;
but it shows:
但它显示:
postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL;
ERROR: syntax error at or near "NULL"
LINE 1: ALTER TABLE person ALTER COLUMN phone SET NULL;
回答by a_horse_with_no_name
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
More details in the manual: http://www.postgresql.org/docs/9.1/static/sql-altertable.html
手册中的更多详细信息:http: //www.postgresql.org/docs/9.1/static/sql-altertable.html
回答by Rigin Oommen
Execute the command in this format
以这种格式执行命令
ALTER TABLE tablename ALTER COLUMN columnname SET NOT NULL;
for setting the column to not null.
用于将列设置为非空。
回答by jainvikram444
First, Set :
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
回答by Sunny Chawla
Execute the command in this format:ALTER [ COLUMN ] column { SET | DROP } NOT NULL
以这种格式执行命令:ALTER [ COLUMN ] column { SET | DROP } NOT NULL