title: Insert data to column which has two relationships
body: <p>So, what I want to do in here is I want to insert the data to table1 who has 'username' field, and this 'username' field has two relationships, which is go to student table and teacher table. But, when I insert the data to user table, I have a problem, and the problem caused by this 'username' field. It caused because the data of 'username' field is not the same as a unique key in student table, and when I change it and made the data same, I get an error too, but this time the data is not the same as a unique in teacher table. So, is it possible to make this 'username' field just get one of the table, like if one of student table and teacher table's data is in 'username', it still can be used. Or maybe this is wrong because of bad ERD? Here's my ERD, if you're asking it:</p>
  
  <p><a href="https://i.stack.imgur.com/eMu2k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eMu2k.png" alt="enter image description here"></a></p>
  
  <p>And well, I know this is really, really bad idea but I made the name in teacher table and student table become a unique key, because I can't create foreign key if I didn't do that. Please, I'm really thankful to your answer.</p>
  
  <p>Here's the ddl for that 3 tables :</p>
  
  <p>Student table :</p>
  
  <pre><code>CREATE TABLE [dbo].[student](
  [studentid] [int] IDENTITY(2016000001,1) NOT NULL,
  [name] [varchar](50) NOT NULL,
  [address] [text] NOT NULL,
  [gender] [varchar](7) NOT NULL,
  [dateofbirth] [date] NOT NULL,
  [nohp] [varchar](13) NOT NULL,
  
  
  CONSTRAINT [PK_student] PRIMARY KEY CLUSTERED 
  (
  [studentid] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
  
  
  CONSTRAINT [IX_student] UNIQUE NONCLUSTERED 
  (
  [name] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  GO
  </code></pre>
  
  <p>Teacher Table :</p>
  
  <pre><code>CREATE TABLE [dbo].[teacher](
  [teacherid] [int] IDENTITY(1,1) NOT NULL,
  [name] [varchar](50) NOT NULL,
  [gender] [varchar](7) NOT NULL,
  
  CONSTRAINT [PK_teacher] PRIMARY KEY CLUSTERED 
  
  (
      [teacherid] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
   CONSTRAINT [IX_teacher] UNIQUE NONCLUSTERED 
  (
      [name] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  </code></pre>
  
  <p>User table:</p>
  
  <pre><code>CREATE TABLE [dbo].[user](
  [userid] [int] IDENTITY(1,1) NOT NULL,
  [username] [varchar](50) NOT NULL,
  [password] [varchar](20) NOT NULL,
  [role] [varchar](10) NOT NULL,
   CONSTRAINT [PK_user] PRIMARY KEY CLUSTERED 
  (
      [userid] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  GO
  
  ALTER TABLE [dbo].[user]  WITH CHECK ADD  CONSTRAINT [FK_user_student] FOREIGN KEY([username])
  REFERENCES [dbo].[student] ([name])
  ON DELETE CASCADE
  GO
  
  ALTER TABLE [dbo].[user] CHECK CONSTRAINT [FK_user_student]
  GO
  
  ALTER TABLE [dbo].[user]  WITH CHECK ADD  CONSTRAINT [FK_user_teacher] FOREIGN KEY([username])
  REFERENCES [dbo].[teacher] ([name])
  ON DELETE CASCADE
  GO
  
  ALTER TABLE [dbo].[user] CHECK CONSTRAINT [FK_user_teacher]
  GO
  </code></pre>