-1

Enter image description here

When I tried to Insert this

Insert into Title
    (ISBN, Title, CategoryCode, PublisherCode, SuggestedPrice, NumberInStock)
Values
    ('1021031040', 'PL SQL', 1, 200, 75.50, 10)

I got this message and I could not figure it out. Could someone help me, please?

Msg 547, Level 16, State 0, Line 4 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Title_PublisherCode_To_Publisher_PublisherCode". The conflict occurred in database "Lab2A_Daisuke_Sato", table "dbo.Publisher", column 'PublisherCode'.

Dale K
  • 25,246
  • 15
  • 42
  • 71
orion
  • 3
  • 3
  • 1
    There is no PublisherCode 200 in your Publisher table. That is the reason you cannot insert into the title table with such a code. It has to exist. That is actually a basic SQL principle. You should take a SQL tutorial. – juergen d Oct 13 '21 at 05:23
  • 1
    @DaleK I'm not going to bother asking the asnwerer below because they obvs don't care, but how is this not an exact dupe?? – Charlieface Oct 13 '21 at 06:19
  • @DaleK No I didn't know, congratulations. Use it well (like voting: early and often) – Charlieface Oct 13 '21 at 06:25

1 Answers1

0

Here is your insert statement:

INSERT INTO Title (ISBN, Title, CategoryCode, PublisherCode, SuggestedPrice, NumberInStock)
VALUES ('1021031040', 'PL SQL', 1, 200, 75.50, 10);

The error message seems to be saying that there is no record in the publisher table whose primary key is 200. That is, your insert is referring to a publisher record which does not exist. The remedy would be to either not do this insert, or to add a record to the publisher table with an id of 200.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360