繁体   English   中英

如何将表字段的默认值设置为0.00?

[英]How to set Default value of table field to 0.00?

我在MySql数据库中创建了一个名为“salary_mst”的表。 表字段是

id -> auto increment
name -> varchar(50)
salary -> double

现在如果有人不在工资中插入值,它应该存储默认值0.00我该怎么做?

ALTER TABLE `table`  ADD COLUMN `column` FLOAT(10,2) NOT NULL DEFAULT '0.00'
create table salary_mst (
    id int not null primary key auto_increment,
    name varchar(50),
    salary double not null default 0
);

去测试:

insert into salary_mst (name) values ('foo');
select * from salary_mst;
+----+------+--------+
| id | name | salary |
+----+------+--------+
|  1 | foo  |      0 |
+----+------+--------+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM