15
我在MySql数据库中创建了一个名为“salary_mst”的表。 表字段如何将表格字段的默认值设置为0.00?
id -> auto increment
name -> varchar(50)
salary -> double
现在,如果有人不薪水插入值,就应该保存默认的0.00 我怎么能这样做?
我在MySql数据库中创建了一个名为“salary_mst”的表。 表字段如何将表格字段的默认值设置为0.00?
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 |
+----+------+--------+
如果你输入了这个称号在谷歌,你可以找到很多答案。 :-) –
我发现这个页面是谷歌的第一个结果,所以他的“懒惰”刚刚帮助了我:-)因此,这样的小细节可以击败文档和手册! –