Insert default value when parameter is null

后端 未结 16 2393
遥遥无期
遥遥无期 2020-12-24 05:27

I have a table that has a column with a default value:

create table t (
    value varchar(50) default (\'something\')
)

I\'m using a stored

16条回答
  •  时光取名叫无心
    2020-12-24 05:55

    As far as I know, the default value is only inserted when you don't specify a value in the insert statement. So, for example, you'd need to do something like the following in a table with three fields (value2 being defaulted)

    INSERT INTO t (value1, value3) VALUES ('value1', 'value3')
    

    And then value2 would be defaulted. Maybe someone will chime in on how to accomplish this for a table with a single field.

提交回复
热议问题