Click here to Skip to main content
15,900,818 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
create table Borrows(
bookid varchar(20) not null primary key,
bid varchar(50) not null,
check_out_date date not null,
returndate date not null,
foreign key (bookid) references Book(Bookid),
foreign key (bid) references Borrower(bid),
)
insert into Borrows values('ab100','cs01','2019-02-02','2019-02-12')
insert into Borrows values('ab101','cs02','2019-03-10','2019-03-13')
select * from borrows
out put
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Borrows__bid__3B75D760". The conflict occurred in database "databaselibrary", table "dbo.borrower", column 'bid'.
The statement has been terminated.

(1 row(s) affected)

What I have tried:

i tried to change datatypes of the entry elements
Posted
Updated 27-Jan-19 10:54am

The error is saying that the bid column with value cs02 does not exists in the Borrower table. If you look at the Borrows table again,
foreign key (bid) references Borrower(bid)
it clearly stated that the bid column should reference the bid in Borrower table. Hope that helps. If not, please ask.

Note: I'm assuming cs02 but it could be c201 in your case.
 
Share this answer
 
v2
Quote:
what is the problem?

This is the problem:
Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Borrows__bid__3B75D760". The conflict occurred in database "databaselibrary", table "dbo.borrower", column 'bid'.

This mean that 1 of the bid does not exist in borrower data table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900