I’m designing a library database schema, let’s say there is a book, it belongs to several subjects, how to design the column to store those subjects? use nvarchar to store the subjectId(s)?
---------
Book
---------
id ----- int
title ----- nvarchar(50)
subjectId ----- int (foreign key to Subject table)
---------
Subject
---------
id ----- int
name ----- nvarchar(50)
NO, the proper way to do this is to add another table that contains the relationships. Here is an article that explains it http://www.tomjewett.com/dbdesign/dbdesign.php?page=manymany.php