开发者

How to set Default value of table field to 0.00?

开发者 https://www.devze.com 2023-04-05 21:04 出处:网络
I have created a table named \"salary_mst\" in MySql database.开发者_StackOverflow Table fields are

I have created a table named "salary_mst" in MySql database.开发者_StackOverflow Table fields are

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

Now if someone don't insert value in salary, it should store default 0.00 How can I do that ?


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
);

To test:

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

精彩评论

暂无评论...
验证码 换一张
取 消