You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
601 B
MySQL
21 lines
601 B
MySQL
7 days ago
|
PRAGMA foreign_keys=1;
|
||
|
CREATE TABLE example (
|
||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||
|
title TEXT NOT NULL,
|
||
|
content TEXT NOT NULL,
|
||
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
|
expires_at DATETIME NOT NULL
|
||
|
);
|
||
|
|
||
|
-- Add an index on the created column.
|
||
|
CREATE INDEX idx_example_created ON example(created_at);
|
||
|
|
||
|
-- Add a trigger to keep timestamp updated.
|
||
|
CREATE TRIGGER snippet_example_timestamp
|
||
|
AFTER UPDATE ON example
|
||
|
FOR EACH ROW
|
||
|
BEGIN
|
||
|
UPDATE example SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||
|
END;
|