Linking the Tables

To link the tables together, we need to modify the table first in order to assign Foreign Key in GenreId column that being related to Id column in Genre table.

ALTER TABLE Song
ADD CONSTRAINT FK_SongGenre FOREIGN KEY (GenreId)
REFERENCES Genre(Id) ON DELETE CASCADE
  • Alter table being used to modify the columns in certain table.
  • Add constraint refers to assign a Foreign Key named FK_SongGenre into GenreId.
  • Then, this key will get referenced to Id column in Genre table.
  • On Delete Cascade specifies an action if a record in the parent table is deleted, than the corresponding record on child table will be deleted automatically.

results matching ""

    No results matching ""