CREATE TABLE images (
image_id INTEGER AUTO_INCREMENT PRIMARY KEY,
filename VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE tags (
tag_id INTEGER AUTO_INCREMENT PRIMARY KEY,
tag VARCHAR(255) NOT NULL UNIQUE
);
CREATE TABLE images_tags (
image_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
PRIMARY KEY (tag_id, image_id),
FOREIGN KEY (tag_id) REFERENCES tags(tag_id),
FOREIGN KEY (image_id) REFERENCES images(image_id)
);