user1544102
user1544102

Reputation: 99

Is there any way to set the default value of all columns in a mysql database at a time?

Is there any way to set all the columns(int) default value at a time, in single query?

Upvotes: 2

Views: 4594

Answers (1)

xception
xception

Reputation: 4287

Yes

ALTER TABLE table_name
    ALTER COLUMN column_name datatype DEFAULT value

An example with int

ALTER TABLE table_name
    ALTER COLUMN column_name int DEFAULT 0;

If you actually wanted to change all the values in the table to a value instead, use:

UPDATE table_name
    SET column_name = value;

And if you wanted to change let's say all entries having old_value to new_value for column_name:

UPDATE table_name
    SET column_name = new_value 
    WHERE column_name = old_value;

Please formulate your question more clearly.

Upvotes: 2

Related Questions