5.5.5. Changing a Column's Default Value

5.5.5. Changing a Column's Default Value
5.5.5.改变列的默认值
To set a new default for a column, use a command like:
重设列的默认值,命令如下:
 
ALTER TABLE products ALTER COLUMN price SET DEFAULT 7.77;
 
Note that this doesn't affect any existing rows in the table, it just changes the default for future INSERT  commands.
请注意,这仅对新插入的数据有效,而对已有列不会产生影响。
 
To remove any default value, use:
删除默认值命令:
 
ALTER TABLE products ALTER COLUMN price DROP DEFAULT;
 
This is effectively the same as setting the default to null. As a consequence, it is not an error to drop  a default where one hadn't been defined, because the default is implicitly the null value.
这实际上与将默认值设置为null相同。所以,因为默认值隐式为空值,所以在没有定义默认值的地方删除默认值并不会抛出错误。
发布了341 篇原创文章 · 获赞 53 · 访问量 88万+

猜你喜欢

转载自blog.csdn.net/ghostliming/article/details/104369309