insert DEFAULT values

做~自己de王妃 提交于 2020-01-02 01:07:48

问题


Is there ANY difference between those two statements?:

INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets');

and:

INSERT INTO distributors (dname) VALUES ('XYZ Widgets');

I mean is there at least one reason to use one or another pattern in some particular situation or is it completely the same? did is a serial column.


回答1:


It's exactly the same thing. No need to pick one instead of the other.

Usually default keyword is handy when you have computer-generated code. It makes life easier to just use every single column in the insert clause and just use default when you don't have a specific value for certain column.

Other than that, as I said, it's the same.




回答2:


INSERT INTO distributors (dname) VALUES ('XYZ Widgets');

This is fine, you do not need to specify a field if you want its default value being saved, provided a default is set.



来源:https://stackoverflow.com/questions/14602992/insert-default-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!