Reputation: 105
I've a table item
that has some columns that are nullable
.
To one of them type
, I'd like to automatically insert a default
value (instead of a NULL
) whenever a new record in inserted in the table and do not specify a value for that column.
Can it be done without affecting the existing data?
The type
column is a varchar
.
I can update the current nulls
.
Upvotes: 2
Views: 2353
Reputation: 169
This query will work for you.
For update table.
ALTER TABLE `column_name` CHANGE `tab` `my_id` INT(11) NOT NULL DEFAULT '0';
For insert table
CREATE TABLE `db_name`.`Tbale_name` ( `demo` INT NOT NULL DEFAULT '0');
Upvotes: 1