r/mysql•
naikkeatas

Add column with default value but let the existing data be null?

question

so i wanna add timestamp columns on the existing table like this

ALTER TABLE `request_history` 
ADD COLUMN `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP 
ADD COLUMN `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

so for any new data, it will automatically fill with the current timestamp on both INSERT and UPDATE

but, afaik, using this query, it will fill the existing data with the ALTER TABLE current timestamp on both columns

I want both columns on the existing data to be null, is there a way to do that without manually updating existing data using UPDATE?

Posted Jul 29, 2025, 6:25 AM UTC

12
Loading comments…