0

I want to create a column with default value as null and when any operation is performed it should change to 0. How do i do this in mysql database?

asked Aug 9, 2014 at 6:11
1
  • measn I have to update that column to 0 on function call... Commented Aug 9, 2014 at 6:14

2 Answers 2

1

Here example how to add colum in existing table with default value

ALTER TABLE `test1` ADD `no` INT NULL DEFAULT NULL ;

When you call function then you have to write following query

UPDATE test1 SET `no` = '0' WHERE `test1`.`id` =your_id;
answered Aug 9, 2014 at 6:19

3 Comments

i already have a table. and i want to add column with default value null.
say add column with default value null to existing table
@KedarB when you ask question then mention all these things
0
CREATE TABLE test 
(
id INT NOT NULL AUTO_INCREMENT, 
PRIMARY KEY(id),
test_id INT,
cost FLOAT(5,2) DEFAULT NULL,
);

each time when you do some operation on that you need to update it as @Sadikhasan

or write a trigger that will update it to zero automatically.

if the operation you want to perform is read then write trigger on ON SELECT

if the operation you want to perform is update then write trigger on ON UPDATE

like wise for others.

answered Aug 9, 2014 at 6:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.