We help IT Professionals succeed at work.

sql workbench

mikha
mikha asked
on
I'm working with sql workbench and still figuring things out.

How to set up a , created and updated column , with datetime value and have created date automatically set , when row is created and update the updated column everytime the row updates.

also , how to set up a default value for a column

I am trying to do this using GUI of sql workbench .
Comment
Watch Question

Nick UpsonPrincipal Operations Engineer

Commented:
so workbench is the tool you are using to access what database (which makes all the difference), e.g.postfix. oracle. firebird, sqllite, .....

Author

Commented:
MySQL version 5.7
Kevin CrossChief Technology Officer
Most Valuable Expert 2011

Commented:
Are you referring to SQL Workbench/J or MySQL Workbench or other tool?

Note: you can do this from SQL syntax typically to set the initial default then you can use a Trigger on updates to update the column if your application doesn't send this automatically.
Chief Technology Officer
Most Valuable Expert 2011
Commented:
Sorry I should have refreshed the page.
For MySQL, you can use either DEFAULT CURRENT_TIMESTAMP, ON UPDATE CURRENT_TIMESTAMP, or both.

CREATE TABLE t1 (
  ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  dt DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Open in new window


Reference: https://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html