Skip to content

Instantly share code, notes, and snippets.

@atomize
Created April 8, 2012 21:36
Show Gist options
  • Save atomize/2339926 to your computer and use it in GitHub Desktop.
Save atomize/2339926 to your computer and use it in GitHub Desktop.
SQLite3 - Create a table with a Column that always holds the CURRENT TIME

#Background: ##SQLite3 - Create a table with a Column that always holds the CURRENT TIME

####tbl_w_currentTimeCol.sqlite

The DEFAULT constraint specifies a default value to use when doing an INSERT. The value may be NULL, a string constant, a number, or a constant expression enclosed in parentheses. The default value may also be one of the special case-independant keywords CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP. If the value is NULL, a string constant or number, it is inserted into the column whenever an INSERT statement that does not specify a value for the column is executed. If the value is CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the current UTC date and/or time is inserted into the columns. For CURRENT_TIME, the format is HH:MM:SS. For CURRENT_DATE, YYYY-MM-DD. The format for CURRENT_TIMESTAMP is "YYYY-MM-DD HH:MM:SS".

create table tbl1(id int primary key, dt datetime default current_timestamp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment