From e7eaa7ff396723ce93d73f275e7ed156d059b07f Mon Sep 17 00:00:00 2001 From: yo mama Date: Thu, 25 Sep 2014 21:34:30 -0700 Subject: test --- many_to_many_example.postgres | 16 ++++++++++++++++ manytomany_sqlite.sql | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 many_to_many_example.postgres create mode 100644 manytomany_sqlite.sql diff --git a/many_to_many_example.postgres b/many_to_many_example.postgres new file mode 100644 index 0000000..6a4ef56 --- /dev/null +++ b/many_to_many_example.postgres @@ -0,0 +1,16 @@ +CREATE TABLE cds( +id serial PRIMARY KEY -- implicit primary key constraint, +title text NOT NULL +); + +CREATE TABLE artists( +id serial PRIMARY KEY, +name text NOT NULL +); + +CREATE TABLE cds_and_artists( +cds_id integer REFERENCES cds (id) ON UPDATE CASCADE ON DELETE CASCADE, +artists_id integer REFERENCES artisys (id) ON UPDATE CASCADE, +CONSTRAINT cds_and_artists_pkey PRIMARY KEY (cds_id, artists_id) +); + diff --git a/manytomany_sqlite.sql b/manytomany_sqlite.sql new file mode 100644 index 0000000..2546b5f --- /dev/null +++ b/manytomany_sqlite.sql @@ -0,0 +1,16 @@ +CREATE TABLE cds( + id INTEGER PRIMARY KEY NOT NULL, + title TEXT NOT NULL +); +CREATE TABLE artists( + id INTEGER PRIMARY KEY NOT NULL, + name TEXT NOT NULL +); +CREATE TABLE cds_and_artists( + cds_id INTEGER, + artists_id INTEGER, + FOREIGN KEY(cds_id) REFERENCES cds(id) ON DELETE CASCADE, + FOREIGN KEY(artists_id) REFERENCES artists(id) ON DELETE CASCADE +); +CREATE INDEX cdsindex ON cds_and_artists(cds_id); +CREATE INDEX artistsindex ON cds_and_artists(artists_id); -- cgit v1.2.3-70-g09d2