Skip to content

Instantly share code, notes, and snippets.

@andrewrcollins
Created April 10, 2017 02:21
Show Gist options
  • Save andrewrcollins/732326c17e1eec2ce15737d0a06f299d to your computer and use it in GitHub Desktop.
Save andrewrcollins/732326c17e1eec2ce15737d0a06f299d to your computer and use it in GitHub Desktop.
simple tagging
CREATE TABLE tag
(
id INT(10) unsigned NOT NULL auto_increment,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY tag_name (name)
);
CREATE TABLE tag_type
(
id INT(10) unsigned NOT NULL auto_increment,
name VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tag_object
(
id INT(10) unsigned NOT NULL auto_increment,
tag_id INT(10) unsigned NOT NULL,
tag_type_id INT(10) unsigned NOT NULL,
object_id INT(10) unsigned NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (tag_id) REFERENCES tag(id) ON DELETE CASCADE,
FOREIGN KEY (tag_type_id) REFERENCES tag_type(id) ON DELETE CASCADE
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment