Page 66 - SQL
P. 66

BooksAuthors



        (view table)


          BookId    AuthorId


          1         1

          2         1


          3         1

          4         2


          5         2


          6         3

          7         4


          7         5

          7         6


          7         7


          7         8


        SQL to create the table:


         CREATE TABLE BooksAuthors (
             AuthorId INT NOT NULL,
             BookId  INT NOT NULL,
             FOREIGN KEY (AuthorId) REFERENCES Authors(Id),
             FOREIGN KEY (BookId) REFERENCES Books(Id)
         );

         INSERT INTO BooksAuthors
             (BookId, AuthorId)
         VALUES
             (1, 1),
             (2, 1),
             (3, 1),
             (4, 2),
             (5, 2),
             (6, 3),
             (7, 4),
             (7, 5),
             (7, 6),
             (7, 7),
             (7, 8)
         ;





        https://riptutorial.com/                                                                               48
   61   62   63   64   65   66   67   68   69   70   71