Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MySQL: convert all DATETIME to TIMESTAMP
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