+ references to non-PKs
authorEric Prud'hommeaux <eric@w3.org>
Mon, 19 Mar 2012 14:50:43 -0400
changeset 75 e5e960ae17e7
parent 74 5a6368032f1e
child 76 0ea30c3b2d17
+ references to non-PKs
ref-all-nulls/create.sql
ref-all-nulls/directGraph.ttl
ref-no-pk/create.sql
ref-no-pk/directGraph.ttl
ref-not-pk/create.sql
ref-not-pk/directGraph.ttl
ref-some-nulls/create.sql
ref-some-nulls/directGraph.ttl
spec-ref-no-pk/create.sql
spec-ref-no-pk/directGraph.ttl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-all-nulls/create.sql	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,33 @@
+CREATE TABLE "Target" (
+	"PK" INT,
+	PRIMARY KEY("PK"),
+	"key1attr1" CHAR(5),
+	"key1attr2" CHAR(5),
+	UNIQUE ("key1attr1", "key1attr2"),
+	"key2attr1" CHAR(5),
+	"key2attr2" CHAR(5),
+	UNIQUE ("key2attr2", "key2attr1")
+);
+
+CREATE TABLE "Source" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"attrA" CHAR(5),
+	"attrB" CHAR(5),
+	FOREIGN KEY ("attrA", "attrB") REFERENCES "Target"("key2attr2", "key2attr1")
+);
+
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1010, 'K1A11'    , 'K1A21'    , 'K2A11'    , 'K2A21'    );
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1011, 'K1A12'    , 'K1A22'    , NULL       , 'K2A22'    );
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1012, 'K1A13'    , 'K1A23'    , NULL       , NULL       );
+
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1100, 'K2A21', 'K2A11');
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1101, 'K2A22', NULL   );
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1102, NULL   , NULL   );
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-all-nulls/directGraph.ttl	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,35 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<Target/PK-1010> a <Target> .
+<Target/PK-1010> <Target#PK> 1010 .
+<Target/PK-1010> <Target#key1attr1> "K1A11" .
+<Target/PK-1010> <Target#key1attr2> "K1A21" .
+<Target/PK-1010> <Target#key2attr1> "K2A11" .
+<Target/PK-1010> <Target#key2attr2> "K2A21" .
+
+<Target/PK-1011> a <Target> .
+<Target/PK-1011> <Target#PK> 1011 .
+<Target/PK-1011> <Target#key1attr1> "K1A12" .
+<Target/PK-1011> <Target#key1attr2> "K1A22" .
+<Target/PK-1011> <Target#key2attr2> "K2A22" .
+
+<Target/PK-1012> a <Target> .
+<Target/PK-1012> <Target#PK> 1012 .
+<Target/PK-1012> <Target#key1attr1> "K1A13" .
+<Target/PK-1012> <Target#key1attr2> "K1A23" .
+
+<Source/ID-1100> a <Source> .
+<Source/ID-1100> <Source#ID> 1100 .
+<Source/ID-1100> <Source#attrA> "K2A21" .
+<Source/ID-1100> <Source#attrB> "K2A11" .
+<Source/ID-1100> <Source#ref-attrA.attrB> <Target/PK-1010> .
+
+<Source/ID-1101> a <Source> .
+<Source/ID-1101> <Source#ID> 1101 .
+<Source/ID-1101> <Source#attrA> "K2A22" .
+<Source/ID-1101> <Source#ref-attrA.attrB> <Target/PK-1011> .
+
+<Source/ID-1102> a <Source> .
+<Source/ID-1102> <Source#ID> 1102 .
+<Source/ID-1102> <Source#ref-attrA.attrB> <Target/PK-1012> .
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-no-pk/create.sql	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,24 @@
+CREATE TABLE "Target" (
+	"litattr1" INT,
+	-- PRIMARY KEY("PK"),
+	"key1attr1" CHAR(4),
+	"key1attr2" CHAR(4),
+	UNIQUE ("key1attr1", "key1attr2"),
+	"key2attr1" CHAR(4),
+	"key2attr2" CHAR(4),
+	UNIQUE ("key2attr2", "key2attr1")
+);
+
+CREATE TABLE "Source" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"attrA" CHAR(4),
+	"attrB" CHAR(4),
+	FOREIGN KEY ("attrA", "attrB") REFERENCES "Target"("key2attr2", "key2attr1")
+);
+
+INSERT INTO "Target" ("litattr1", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1010      , 'K1A1'     , 'K1A2'     , 'K2A1'     , 'K2A2');
+
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1100, 'K2A2' , 'K2A1' );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-no-pk/directGraph.ttl	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,15 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+_:a a <Target> .
+_:a <Target#litattr1> 1010 .
+_:a <Target#key1attr1> "K1A1" .
+_:a <Target#key1attr2> "K1A2" .
+_:a <Target#key2attr1> "K2A1" .
+_:a <Target#key2attr2> "K2A2" .
+
+<Source/ID-1100> a <Source> .
+<Source/ID-1100> <Source#ID> 1100 .
+<Source/ID-1100> <Source#attrA> "K2A2" .
+<Source/ID-1100> <Source#attrB> "K2A1" .
+<Source/ID-1100> <Source#ref-attrA.attrB> _:a .
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-not-pk/create.sql	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,24 @@
+CREATE TABLE "Target" (
+	"PK" INT,
+	PRIMARY KEY("PK"),
+	"key1attr1" CHAR(4),
+	"key1attr2" CHAR(4),
+	UNIQUE ("key1attr1", "key1attr2"),
+	"key2attr1" CHAR(4),
+	"key2attr2" CHAR(4),
+	UNIQUE ("key2attr2", "key2attr1")
+);
+
+CREATE TABLE "Source" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"attrA" CHAR(4),
+	"attrB" CHAR(4),
+	FOREIGN KEY ("attrA", "attrB") REFERENCES "Target"("key2attr2", "key2attr1")
+);
+
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1010, 'K1A1'     , 'K1A2'     , 'K2A1'     , 'K2A2'     );
+
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1100, 'K2A2' , 'K2A1' );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-not-pk/directGraph.ttl	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,15 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<Target/PK-1010> a <Target> .
+<Target/PK-1010> <Target#PK> 1010 .
+<Target/PK-1010> <Target#key1attr1> "K1A1" .
+<Target/PK-1010> <Target#key1attr2> "K1A2" .
+<Target/PK-1010> <Target#key2attr1> "K2A1" .
+<Target/PK-1010> <Target#key2attr2> "K2A2" .
+
+<Source/ID-1100> a <Source> .
+<Source/ID-1100> <Source#ID> 1100 .
+<Source/ID-1100> <Source#attrA> "K2A2" .
+<Source/ID-1100> <Source#attrB> "K2A1" .
+<Source/ID-1100> <Source#ref-attrA.attrB> <Target/PK-1010> .
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-some-nulls/create.sql	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,29 @@
+CREATE TABLE "Target" (
+	"PK" INT,
+	PRIMARY KEY("PK"),
+	"key1attr1" CHAR(5),
+	"key1attr2" CHAR(5),
+	UNIQUE ("key1attr1", "key1attr2"),
+	"key2attr1" CHAR(5),
+	"key2attr2" CHAR(5),
+	UNIQUE ("key2attr2", "key2attr1")
+);
+
+CREATE TABLE "Source" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"attrA" CHAR(5),
+	"attrB" CHAR(5),
+	FOREIGN KEY ("attrA", "attrB") REFERENCES "Target"("key2attr2", "key2attr1")
+);
+
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1010, 'K1A11'    , 'K1A21'    , 'K2A11'    , 'K2A21'    );
+INSERT INTO "Target" ("PK", "key1attr1", "key1attr2", "key2attr1", "key2attr2")
+              VALUES (1011, 'K1A12'    , 'K1A22'    , NULL       , 'K2A22'    );
+
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1100, 'K2A21', 'K2A11');
+INSERT INTO "Source" ("ID", "attrA", "attrB")
+              VALUES (1101, 'K2A22', NULL   );
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ref-some-nulls/directGraph.ttl	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,26 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<Target/PK-1010> a <Target> .
+<Target/PK-1010> <Target#PK> 1010 .
+<Target/PK-1010> <Target#key1attr1> "K1A11" .
+<Target/PK-1010> <Target#key1attr2> "K1A21" .
+<Target/PK-1010> <Target#key2attr1> "K2A11" .
+<Target/PK-1010> <Target#key2attr2> "K2A21" .
+
+<Target/PK-1011> a <Target> .
+<Target/PK-1011> <Target#PK> 1011 .
+<Target/PK-1011> <Target#key1attr1> "K1A12" .
+<Target/PK-1011> <Target#key1attr2> "K1A22" .
+<Target/PK-1011> <Target#key2attr2> "K2A22" .
+
+<Source/ID-1100> a <Source> .
+<Source/ID-1100> <Source#ID> 1100 .
+<Source/ID-1100> <Source#attrA> "K2A21" .
+<Source/ID-1100> <Source#attrB> "K2A11" .
+<Source/ID-1100> <Source#ref-attrA.attrB> <Target/PK-1010> .
+
+<Source/ID-1101> a <Source> .
+<Source/ID-1101> <Source#ID> 1101 .
+<Source/ID-1101> <Source#attrA> "K2A22" .
+<Source/ID-1101> <Source#ref-attrA.attrB> <Target/PK-1011> .
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec-ref-no-pk/create.sql	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,67 @@
+CREATE TABLE "Addresses" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"city" VARCHAR(10),
+	"state" CHAR(2)
+);
+
+CREATE TABLE "Department" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"name" VARCHAR(10),
+	"city" VARCHAR(10),
+	UNIQUE ("name", "city"),
+	"manager" INT,
+	FOREIGN KEY ("manager") REFERENCES "People"("ID")
+);
+
+CREATE TABLE "People" (
+	"ID" INT,
+	PRIMARY KEY("ID"),
+	"fname" VARCHAR(10),
+	"addr" INT,
+	FOREIGN KEY ("addr") REFERENCES "Addresses"("ID"),
+	"deptName" VARCHAR(10),
+	"deptCity" VARCHAR(10),
+	FOREIGN KEY ("deptName", "deptCity") REFERENCES "Department"("name", "city")
+);
+
+INSERT INTO "Addresses" ("ID", "city",      "state")
+                 VALUES (18,   'Cambridge', 'MA');
+
+INSERT INTO "People" ("ID", "fname", "addr", "deptName", "deptCity" )
+              VALUES (8,    'Sue',   NULL,   NULL,       NULL);
+
+INSERT INTO "Department" ("ID", "name",       "city",      "manager")
+                  VALUES (23,   'accounting', 'Cambridge', 8);
+
+INSERT INTO "People" ("ID", "fname", "addr", "deptName",   "deptCity" )
+              VALUES (7,    'Bob',   18,     'accounting', 'Cambridge');
+
+CREATE TABLE "Projects" (
+	"lead" INT,
+	FOREIGN KEY ("lead") REFERENCES "People"("ID"),
+	"name" VARCHAR(50), 
+	UNIQUE ("lead", "name"), 
+	"deptName" VARCHAR(50), 
+	"deptCity" VARCHAR(50),
+	UNIQUE ("name", "deptName", "deptCity"),
+	FOREIGN KEY ("deptName", "deptCity") REFERENCES "Department"("name", "city")
+);
+CREATE TABLE "TaskAssignments" (
+	"worker" INT,
+	FOREIGN KEY ("worker") REFERENCES "People"("ID"),
+	"project" VARCHAR(50), 
+	PRIMARY KEY ("worker", "project"), 
+	"deptName" VARCHAR(50), 
+	"deptCity" VARCHAR(50),
+	FOREIGN KEY ("worker") REFERENCES "People"("ID"),
+	FOREIGN KEY ("project", "deptName", "deptCity") REFERENCES "Projects"("name", "deptName", "deptCity"),
+	FOREIGN KEY ("deptName", "deptCity") REFERENCES "Department"("name", "city")
+);
+INSERT INTO  "Projects" ("lead", "name",          "deptName",   "deptCity" )
+                 VALUES (8,      'pencil survey', 'accounting', 'Cambridge');
+INSERT INTO  "Projects" ("lead", "name",          "deptName",   "deptCity" )
+                 VALUES (8,      'eraser survey', 'accounting', 'Cambridge');
+INSERT INTO "TaskAssignments" ("worker", "project",       "deptName",   "deptCity" )
+                       VALUES (7,        'pencil survey', 'accounting', 'Cambridge');
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec-ref-no-pk/directGraph.ttl	Mon Mar 19 14:50:43 2012 -0400
@@ -0,0 +1,50 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<People/ID-7> a <People> .
+<People/ID-7> <People#ID> 7 .
+<People/ID-7> <People#fname> "Bob" .
+<People/ID-7> <People#addr> 18 .
+<People/ID-7> <People#ref-addr> <Addresses/ID-18> .
+<People/ID-7> <People#deptName> "accounting" .
+<People/ID-7> <People#deptCity> "Cambridge" .
+<People/ID-7> <People#ref-deptName.deptCity> <Department/ID-23> .
+<People/ID-8> a <People> .
+<People/ID-8> <People#ID> 8 .
+<People/ID-8> <People#fname> "Sue" .
+
+<Addresses/ID-18> a <Addresses> .
+<Addresses/ID-18> <Addresses#ID> 18 .
+<Addresses/ID-18> <Addresses#city> "Cambridge" .
+<Addresses/ID-18> <Addresses#state> "MA" .
+
+<Department/ID-23> a <Department> .
+<Department/ID-23> <Department#ID> 23 .
+<Department/ID-23> <Department#name> "accounting" .
+<Department/ID-23> <Department#city> "Cambridge" .
+<Department/ID-23> <Department#manager> 8; .
+<Department/ID-23> <Department#ref-manager> <People/ID-8> .
+
+_:c a <Projects> .
+_:c <Projects#lead> 8 .
+_:c <Projects#ref-lead> <People/ID-8> .
+_:c <Projects#name> "pencil survey" .
+_:c <Projects#deptName> "accounting" .
+_:c <Projects#deptCity> "Cambridge" .
+_:c <Projects#ref-deptName.deptCity> <Department/ID-23> .
+
+_:d a <Projects> .
+_:d <Projects#lead> 8 .
+_:d <Projects#ref-lead> <People/ID-8> .
+_:d <Projects#name> "eraser survey" .
+_:d <Projects#deptName> "accounting" .
+_:d <Projects#deptCity> "Cambridge" .
+_:d <Projects#ref-deptName.deptCity> <Department/ID-23> .
+
+<TaskAssignments/worker-7.project-pencil%20survey> a <TaskAssignments> .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#worker> 7 .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#ref-worker> <People/ID-7> .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#project> "pencil survey" .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#deptName> "accounting" .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#deptCity> "Cambridge" .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#ref-deptName.deptCity> <Department/ID-23> .
+<TaskAssignments/worker-7.project-pencil%20survey> <TaskAssignments#ref-project.deptName.deptCity> _:c .
\ No newline at end of file