Changes create.sql for spec-ref-no-pk

Eric

create.sql for spec-ref-no-pk does not run automatically given that the
table Department has a FK to People and People has a FK to Department.

Can that be changed to use alter tables instead.

CREATE TABLE "Addresses" (
"ID" INT,
PRIMARY KEY("ID"),
 "city" VARCHAR(10),
"state" CHAR(2)
);

CREATE TABLE "Department" (
"ID" INT,
PRIMARY KEY("ID"),
 "name" VARCHAR(50),
"city" VARCHAR(50),
UNIQUE ("name", "city"),
 "manager" INT
);

CREATE TABLE "People" (
"ID" INT,
 PRIMARY KEY("ID"),
"fname" VARCHAR(10),
"addr" INT,
 FOREIGN KEY ("addr") REFERENCES "Addresses"("ID"),
"deptName" VARCHAR(50),
 "deptCity" VARCHAR(50)
);

ALTER TABLE "Department" ADD FOREIGN KEY("manager") REFERENCES
"People"("ID");
ALTER TABLE "People" ADD FOREIGN KEY("deptName", "deptCity") REFERENCES
"Department"("name", "city");

And another issue.. which seems to be a SQL Server: In the table Projects,
which has a FK to Department, has deptName and deptCity with varchar(50)
while the table Department uses varchar(10) for name and city. In Oracle,
this isn't a problem, but in SQL Server, you need can only create foreign
keys to attributes that have the exact datatype (you learn things every
day!!) In the sql snippet that I pasted above, I already changed the
datatypes of name and city to varchar(50).

Thanks
Juan Sequeda
+1-575-SEQ-UEDA
www.juansequeda.com

Received on Wednesday, 21 March 2012 12:45:59 UTC