Hello. I'm stuck in a problem I have. I populated my database for my book tables, but then I realized that the database listed one author for one book. For example, Art History book has to list two authors (author id 1) and (author id 2).
I was told to make a new table with author_id and book_id but the problem didn't go away. Can should I do to fix this problem?
I don't what do I should change to get what I want...
the basic idea is to have a book table and an author table then have a AuthorBook table that hooks the two of them up. That's the gist of the suggestion given to you.
so something like this. I'm getting error messages though when I try to make the foreign key in the inventory table:
so it's like like this:
books
PK-ISBN, edition,
Inventory
PK-ISBN edition
bookauthors
PK-authorid
FK-?
authors
PK:authorid
FK-?
users
PK:userid
FK-?
orderdetails
PK-ISBN, edition
FK-?
I'm getting error on the foreign keys parts...like "Both sides of a relationship must have the same # of columns"
I would just rather keep the tables I have...I'm having conflicts in these last tables:
DECLARE @users TABLE (userID BIGINT, userName VARCHAR(30), password NVARCHAR(30),firstName NVARCHAR(30), lastName NVARCHAR(30), emailAddress NVARCHAR(50))
PRIMARY KEY: USER ID
DECLARE @orders TABLE (orderID BIGINT, orderDateTime DATETIME, userID BIGINT, paymentType VARCHAR(20), paymentAccountNumber NVARCHAR(50))
FOREIGN KEY: USER ID, ORDER ID
DECLARE @orderDetails TABLE (orderID BIGINT, sequence INT, ISBN NVARCHAR(20), edition INT,quantity INT, condition CHAR(1))
PRIMARY KEY: ORDER ID
FOREIGN KEY: ISBN, EDITION
You can't keep the tables you have since you can't use FKs with temp tables or table variables.
however, if for the last table you want FOREIGN KEY: ISBN, EDITION then you need to concatenate the two into one column, perhaps as a computed, persisted column and use that as the PK/FK pair.
However I would encourage you to study what I posted and adapt it to your situation. It is a more industry-standard approach and is free from the problems you are having.