360man
360man

Reputation: 359

Inserting into a table with datetime column

I'm trying to create and use a table with a timestamp field. I tried creating it like this.

CREATE TABLE testdb(timestamp DATETIME, value INT NOT NULL)

I tried inserting into the table with these commands, but they both fail.

INSERT INTO testdb(TIMESTAMP_NOW, 3)
INSERT INTO testdb(GETDATE(), 3)

How do I create a table with a field for a timestamp, and how do I insert into that table?

Upvotes: 1

Views: 2868

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

The correct syntax would have a column list and values:

INSERT INTO testdb (timestamp, value)
    VALUES (GETDATE(), 3);

Upvotes: 3

Related Questions