I have 2 tables:
Authors(id, name, add, DOB) where the fields are INTEGER, CHAR(20), CHAR(20), DATE respectively. Primary key = id.
Books(bid, title, publisher) where the fields are INTEGER, CHAR(20), CHAR(20) respectively. Primary key = bid.
I want to create another table Write with fields aid, bid, datePublished, where:
- aid = INTEGER ... this is actually the id from Authors.
- bid = INTEGER ... this is actually the bid from Books
- Primary Key = (aid, bid).
How do I do this?
I tried the following lines of code, and all of them gave syntax errors:
CREATE TABLE Write (
aid INTEGER,
bid INTEGER, datePublished DATE,
PRIMARY KEY NONCLUSTERED (aid,bid),
FOREIGN KEY (aid) REFERENCES Authors(id),
FOREIGN KEY (bid) REFERENCES Books(bid)
);
CREATE TABLE Write (
aid INTEGER,
bid INTEGER,
datePublished DATE,
PRIMARY KEY (aid,bid)
);