SQL TIMESTAMP数据类型用于存储日期和时间,精确到秒级别。以下是在SQL中使用TIMESTAMP的一些常见操作:
CREATE TABLE mytable (
id INT,
timestamp_column TIMESTAMP
);
INSERT INTO mytable (id, timestamp_column) VALUES (1, CURRENT_TIMESTAMP);
SELECT * FROM mytable WHERE timestamp_column BETWEEN '2022-01-01 00:00:00' AND '2022-01-02 23:59:59';
SELECT * FROM mytable ORDER BY timestamp_column DESC;
SELECT id, DATE_FORMAT(timestamp_column, '%Y-%m-%d %H:%i:%s') AS formatted_timestamp FROM mytable;
UPDATE mytable SET timestamp_column = '2022-01-01 12:00:00' WHERE id = 1;
DELETE FROM mytable WHERE timestamp_column BETWEEN '2022-01-01 00:00:00' AND '2022-01-02 23:59:59';
这些是SQL中使用TIMESTAMP的一些常见操作,但具体的使用方式可能因数据库系统而异。请参考您使用的具体数据库的文档以获取更详细的信息。