Question : MySQL Timestamps

Hi,

I need to run a script that looks for all columns in my database made up of around 40 tables for like "stamp" and then enters the current data/time "Now()" . I also need to alter these columns so that the default value is "current_timestamp".

How would I go about this?

Thanks

Answer : MySQL Timestamps

try this:

1:
2:
3:
4:
5:
6:
7:
8:
9:
SELECT 
	CONCAT("UPDATE `",a.TABLE_SCHEMA,"`.`",a.TABLE_NAME,"` SET `",b.COLUMN_NAME,"`='",NOW(),"'; ALTER TABLE `",a.TABLE_SCHEMA,"`.`",a.TABLE_NAME,"` MODIFY `",b.COLUMN_NAME,"` ",b.DATA_TYPE," NOT NULL DEFAULT CURRENT_TIMESTAMP;") AS `script`
FROM 
	information_schema.TABLES a
	JOIN information_schema.COLUMNS b USING(TABLE_NAME)
WHERE 
	a.TABLE_SCHEMA='db_name' AND 
	a.TABLE_TYPE ='BASE TABLE' AND 
	b.DATA_TYPE LIKE '%stamp%'
Random Solutions  
 
programming4us programming4us