I'm having a doubt about what is the best design for my situation. I have a common table (Attachment), and that table will have many 1:N relationships. In the future another tables eventually will relationship with that table. I think I have two options:
- Create one separated table to each relationship (1:N);
- Create one table with many relationships (0:N);
Example of the first scenario:
CREATE TABLE [Education](
[Id] [int] IDENTITY(1,1) NOT NULL,
[InstitutionName] [nvarchar](100) NOT NULL,
[Degree] [nvarchar](100) NOT NULL,
--other columns
)
CREATE TABLE [EducationAttachment](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FileName] [nvarchar](4000) NOT NULL,
[Path] [nvarchar](4000) NOT NULL,
--other columns
[EducationId] [int] NOT NULL --1:N foreing key
)
CREATE TABLE [Goal] (
[Id] [int] IDENTITY(1,1) NOT NULL,
[Objective] [nvarchar](4000) NOT NULL,
--other columns
)
CREATE TABLE [GoalAttachment](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FileName] [nvarchar](4000) NOT NULL,
[Path] [nvarchar](4000) NOT NULL,
--other columns
[GoalId] [int] NOT NULL --1:N foreing key
)
--FooTable
--FooAttachment
Example of the second scenario:
CREATE TABLE [Attachment](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FileName] [nvarchar](4000) NOT NULL,
[Path] [nvarchar](4000) NOT NULL,
--other columns
[EducationId] [int] NULL --0:N foreing key
[GoalId] [int] NULL --0:N foreing key
[FooId] [int] NULL --0:N foreing key
)
CREATE TABLE [Education](
[Id] [int] IDENTITY(1,1) NOT NULL,
[InstitutionName] [nvarchar](100) NOT NULL,
[Degree] [nvarchar](100) NOT NULL,
--other columns
)
CREATE TABLE [Goal] (
[Id] [int] IDENTITY(1,1) NOT NULL,
[Objective] [nvarchar](4000) NOT NULL,
--other columns
)
--FooTable
What is the best design option? Or another one?