mysql表中设置了default不起作用

参考博客: https://blog.csdn.net/u013476542/article/details/60867415  博主:享受编程_

参考博客: https://blog.csdn.net/sdxushuxun/article/details/78962521  博主:sdxushuxun

我平时在设置表格时,例如设置成绩默认值为0,但我传入数据发现数据仍然为null;很是不理解

经过参考查找得出一些小经验,记录一下

1、插入表中数据时,传递的参数为null或者“” 都不可以,他们会直接存入数据表中

2、方便的设置默认值是:在对应的实体类的属性中直接赋值。如同这样的:

class entity{

private int score=100;

//省略下面的getter和setter方法

}

3、但是mysql中默认值的设置该怎么应用呢?

当insert into 插入语句中不对该字段进行操作,即insert中没有该字段时才会使用默认值填充

在使用过程中,default可以跟着check使用

猜你喜欢

转载自blog.csdn.net/sarida/article/details/82965568