-1

I've a table which stores books:

CREATE TABLE `Books` (
  `book_id` int(250) NOT NULL,
  `book_name` varchar(100) NOT NULL,
  `book_author` varchar(10) NOT NULL,
  `book_genre` varchar(100) NOT NULL,
  `book_floor` int(5) NOT NULL,
  `book_shelf` int(255) NOT NULL,
  `book_amount` int(255) NOT NULL,
  `book_available` int(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I want to write a table of users which would have a column for books they borrowed, so it has to store all the information about the book from a Books table and it should be possible to store multiple books. How can I do that?

3

2 Answers 2

2

Use a third table borrowed books which would link books and users

Sign up to request clarification or add additional context in comments.

Comments

1

You have a many to many relationship between users and books. You can't do this with just those 2 tables. You'll need a 'UserBooks' table. This table will have a primary key with user_id and book_id.

So basically, for every book a user has borrowed you'll have a row in this table mapping the user's id to the book id.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.