Original address: http://blog.csdn.net/derryzhang/article/details/5033209
In SQL Server, when creating a table, for time columns we can sometimes specify the default value as the current time (i.e., the default timestamp when the record is generated). For example:
[XHTML]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- CREATE TABLE log (
- Content varchar (256),
- LogTime datetime default GETDATE ()
- )
But how is it implemented in SQLite? Check the documentation that SQLite does not have the getdate () function, but its system built-in function has a datetime (), so you can follow the following syntax to implement the default timestamp:
[XHTML]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- CREATE TABLE log (
- Content varchar (256),
- LogTime datetime default datetime (' Now ')
- )
The answer is no, it will prompt a syntax error. So how do we declare it? As shown below:
[C-sharp]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- CREATE TABLE log (
- Content varchar (256),
- LogTime TIMESTAMP Default Current_timestamp
- )
This can be achieved, but the default time is based on Greenwich Mean time, so the words used in China will be just 8 hours earlier. To solve this problem, we can declare that:
[XHTML]View Plaincopy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" >
- CREATE TABLE log (
- Content varchar (256),
- LogTime TIMESTAMP Default (DateTime (' Now ', ' localtime ')
- )
Test it, everything is OK:)
SQLite implements the default time for the current Time column method (GO)