Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Default value of table field to 0.00?

I have created a table named "salary_mst" in MySql database. 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 ?

like image 302
aslamdoctor Avatar asked Sep 20 '11 07:09

aslamdoctor


People also ask

How do you set a default value to 0?

right click on your database -- select design--select required column--in column properties, general tab you will see the "default value or binding". Mention 0 here.


2 Answers

ALTER TABLE `table`  ADD COLUMN `column` FLOAT(10,2) NOT NULL DEFAULT '0.00'
like image 70
Emil Avatar answered Sep 22 '22 05:09

Emil


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 |
+----+------+--------+
like image 24
Bohemian Avatar answered Sep 25 '22 05:09

Bohemian