Compound foreign keys in linking tables [message #4930] |
Tue, 25 August 2015 21:24 |
rafs
Messages: 69 Registered: May 2015
|
Member |
|
|
Given the tables and relationships below, can you explain how to make the LINK1 relationship work from books to audiences?
I tried by defining a CALCULATED parent field for book to book_audiences with calculated field of CONCAT(book_type, ' ', book_name) AS book_type_name.
It gave me an SQL error.
I also tried with just using book_type as the parent field, unsuccessfully.
Is this possible? I don't see any examples of compound keys in linking tables in your demos.
CREATE TABLE book (
book_type char(3),
book_name character varying(100),
book_desc character varying(1000),
PRIMARY KEY (book_type, book_name)
);
CREATE TABLE audience (
aud_type char(3),
aud_name character varying(100),
aud_desc character varying(1000),
PRIMARY KEY (aud_type, aud_name)
);
CREATE TABLE book_audience (
book_type char(3),
book_name character varying(100),
aud_type char(3),
aud_name character varying(100),
PRIMARY KEY (book_type, book_name, aud_type, aud_name),
FOREIGN KEY (book_type, book_name) references book (book_type, book_name),
FOREIGN KEY (aud_type, aud_name) references audience (aud_type, aud_name)
);
Thanks.
[Updated on: Tue, 25 August 2015 21:24] Report message to a moderator
|
|
|