Skip to content

Instantly share code, notes, and snippets.

@dolmen
Created October 27, 2017 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolmen/bb090dc81138d5a4ad2124565accf287 to your computer and use it in GitHub Desktop.
Save dolmen/bb090dc81138d5a4ad2124565accf287 to your computer and use it in GitHub Desktop.
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