MySQL的CURRENT函數用于獲取當前日期和時間。以下是一些最佳實踐案例:
INSERT INTO table_name (created_at, data) VALUES (CURRENT_TIMESTAMP, 'some_data');
UPDATE table_name SET updated_at = CURRENT_TIMESTAMP WHERE id = 1;
SELECT * FROM table_name WHERE created_at >= CURRENT_DATE;
CREATE TRIGGER trigger_name BEFORE UPDATE ON table_name
FOR EACH ROW SET NEW.updated_at = CURRENT_TIMESTAMP;
CREATE PROCEDURE procedure_name()
BEGIN
DECLARE current_time TIMESTAMP;
SET current_time = CURRENT_TIMESTAMP;
-- do something with current_time
END;
這些是一些使用MySQL的CURRENT函數的最佳實踐案例,可以幫助您更好地利用當前日期和時間來管理數據。