Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Is it possible in a SQLite database to create a table that has a timestamp column that defaults to DATETIME('now')?

Like this:

CREATE TABLE test (

    id INTEGER PRIMARY KEY AUTOINCREMENT, 

    t TIMESTAMP DEFAULT DATETIME('now')

);

This gives an error... How to resolve?

1 Answer

0 votes
by (40.7k points)

Try the code given below:

CREATE TABLE test (

  id INTEGER PRIMARY KEY AUTOINCREMENT,

  t TIMESTAMP

  DEFAULT CURRENT_TIMESTAMP

);

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 12, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2021 in SQL by Appu (6.1k points)
...