SQL TIMESTAMP數(shù)據(jù)類(lèi)型用于存儲(chǔ)日期和時(shí)間,精確到秒級(jí)別。以下是在SQL中使用TIMESTAMP的一些常見(jiàn)操作:
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的一些常見(jiàn)操作,但具體的使用方式可能因數(shù)據(jù)庫(kù)系統(tǒng)而異。請(qǐng)參考您使用的具體數(shù)據(jù)庫(kù)的文檔以獲取更詳細(xì)的信息。