Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting data into SQL Server 2012
    primarykey
    data
    text
    <p>I'm working with SQL Server 2012 </p> <p>I have two tables, <code>Person</code> and <code>Couple</code>, <code>Person</code> has a foreign key from <code>Couple</code> and <code>Couple</code> has foreign key from 'Person'.</p> <p>When I try to insert data into each one, an error occurs because each table has FK from the other table, and both are empty initially.</p> <pre><code>CREATE TABLE [dbo].[Couple]( [CoupleId] [int] IDENTITY(1,1) NOT NULL, [HusbandPersonId] [int] NOT NULL, [WifePersonId] [int] NOT NULL, [StartDate] [date] NOT NULL, [EndDate] [date] NOT NULL, CONSTRAINT [PK_Couple] PRIMARY KEY CLUSTERED ( [CoupleId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] CREATE TABLE [dbo].[Person]( [PersonId] [int] IDENTITY(1,1) NOT NULL, [ChildOfCoupleId] [int] NOT NULL, [CityOfBirth] [int] NOT NULL, [CityOfPermanentResidence] [int] NOT NULL, [CityOfCurrentResidence] [int] NOT NULL, [FirstName] [varchar](20) NOT NULL, [LastName] [varchar](20) NOT NULL, [BirthDate] [date] NOT NULL, [DeathDate] [date] NOT NULL, [IsMale] [bit] NOT NULL, CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED ( [PersonId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY ALTER TABLE [dbo].[Couple] WITH CHECK ADD CONSTRAINT [FK_Couple_Person] FOREIGN KEY([HusbandPersonId]) REFERENCES [dbo].[Person] ([PersonId]) GO ALTER TABLE [dbo].[Couple] CHECK CONSTRAINT [FK_Couple_Person] GO ALTER TABLE [dbo].[Couple] WITH CHECK ADD CONSTRAINT [FK_Couple_Person1] FOREIGN KEY([WifePersonId]) REFERENCES [dbo].[Person] ([PersonId]) GO ALTER TABLE [dbo].[Couple] CHECK CONSTRAINT [FK_Couple_Person1] GO ALTER TABLE [dbo].[Person] WITH CHECK ADD CONSTRAINT [FK_Person_Couple] FOREIGN KEY([ChildOfCoupleId]) REFERENCES [dbo].[Couple] ([CoupleId]) GO ALTER TABLE [dbo].[Person] CHECK CONSTRAINT [FK_Person_Couple] GO </code></pre> <p>How to solve this ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload