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的一些常見操作,但具體的使用方式可能因數據庫系統而異。請參考您使用的具體數據庫的文檔以獲取更詳細的信息。