I have plenty of tables in MySQL which which contains zero date in dateTime column 0000-00-00 00:00:00
Using some sort of admin settings, Is it possibl
You have two options.
Option One - In the programming language of your choice (you can even do this with Stored Procedures):
INFORMATION_SCHEMA
, probably COLUMNS
and build a query to get back the tables you need to affect, i.e.-
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='date' AND TABLE_SCHEMA=''
or maybe even better
SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME in ('timestamp','date','datetime')
AND TABLE_SCHEMA=''
-
@string = CONCAT("UPDATE ", @table_name, " SET ", @column_name, "='1-1-1900' WHERE ", @column_name, "=0000-00-00 00:00:00");
PREPARE stmt FROM @string; EXECUTE stmt;
That wouldn't be too tough to write up.
Option Two - Another example, while certainly more low tech, may be no less effective. After doing a mysqldump
and before doing your export, you can do a simple search-replace in the file. Vim or any other text editor would do this quite expertly and would allow you to replace 0000-00-00 00:00:00 with 1-1-1900. Because you are almost definitely not going to find situations where you DON'T want that to be replaced, this could be the easiest option for you. Just throwing it out there!