In SQL Server, when creating a table, you can specify the default value as the current time (that is, the default timestamp is used when the record is generated) for the Time column ). For example:
Create Table log (content varchar (256), logtime datetime default getdate ())
But how to implement it in SQLite? Check the document and find that SQLite does not have the getdate () function, but its built-in functions include datetime (). So can we implement the default timestamp according to the following statement:
Create Table log (content varchar (256), logtime datetime default datetime ('now '))
The answer is no. A syntax error is prompted. So how should we declare it? As follows:
Create Table log (content varchar (256), logtime timestamp default current_timestamp)
This can achieve the effect, but the default time is based on the GMT standard time, so it will be 8 hours earlier in China. To solve this problem, we can declare:
Create Table log (content varchar (256), logtime timestamp default (datetime ('now ', 'localtime ')))
Test, everything is normal :)