Unsupported Screen Size: The viewport size is too small for the theme to render properly.

Trouble with keys and relationships

forums forums SQLyog Using SQLyog Trouble with keys and relationships

  • This topic is empty.
Viewing 0 reply threads
  • Author
    Posts
    • #14692
      Shadow
      Member

      Your IT friend was right suggesting to use the third table because books and authors have a many-to-many relationship (a book may have several authors and an author may write several books) and relational dbs do not really like such connections. To resolve such situations (they are quite common) a third table is introduced that hold the primary keys of both tables, thus holding every possible combination of the two primary keys. Actually, I don't understand why you use an autoincrement id column in table_books_authors table, book_id and author_id fields combined may serve as primary key.

      How to do it in SQLyog? Just create the table_books_authors table with two columns (book_id, author_id) and mark both columns as primary key.

      As you are new to MySql, I would like to point out that MySql is able to use different storage engines for the tables. The default is MyISAM which – currently – cannot handle relationships. If you want to to use relationships then INNODB storage engine should be used.

Viewing 0 reply threads
  • You must be logged in to reply to this topic.