Created
October 27, 2017 10:55
-
-
Save dolmen/bb090dc81138d5a4ad2124565accf287 to your computer and use it in GitHub Desktop.
MySQL: convert all DATETIME to TIMESTAMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT CONCAT('ALTER TABLE `',TABLE_SCHEMA,'`.`', TABLE_NAME, '` ', GROUP_CONCAT(' MODIFY COLUMN "', COLUMN_NAME, '` TIMESTAMP ',IF(IS_NULLABLE = 'NO','NOT',''),' NULL'),';') | |
FROM INFORMATION_SCHEMA.COLUMNS | |
WHERE TABLE_SCHEMA = DATABASE() | |
AND DATA_TYPE = 'DATETIME' | |
GROUP BY TABLE_SCHEMA, TABLE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment