Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

The INSERT statement conflicted with the FOREIGN KEY constraint(Not reproducible) Expand / Collapse
Author
Message
Posted Monday, April 1, 2013 5:19 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 6:16 AM
Points: 59, Visits: 80
hello sir..can u plz help me .....i don't knw how to solve this conflict ''The INSERT statement conflicted with the FOREIGN KEY constraint "FK_product_details". The conflict occurred in database "catalog", table "dbo.product_details", column 'product_id' ".......
i have 2 tables, product_details and purchase_details.....

CREATE TABLE product_details
(
product_id int identity(1,1) not null,
product_name varchar(500),
product_catagory varchar(100),
CONSTRAINT PK_product_details PRIMARY KEY(product_id)
)

CREATE TABLE purchase_details
(
Purchase_id int not null identity(1,1) ,
product_id int CONSTRAINT FK_product_details FOREIGN KEY REFERENCES product_details(product_id) ,
Product_Name varchar(500),
Product_Cost VARCHAR(500),
Product_Quantity varchar(500),
CONSTRAINT PK_Purchase_details PRIMARY KEY(Purchase_id)
)

when i was try to insert values in 'purchase_details' that error msg displayed.......i dont know wats the mistak there....
Post #1437401
Posted Monday, April 1, 2013 7:58 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:21 PM
Points: 13,083, Visits: 11,918
nitha jen (4/1/2013)
hello sir..can u plz help me .....i don't knw how to solve this conflict ''The INSERT statement conflicted with the FOREIGN KEY constraint "FK_product_details". The conflict occurred in database "catalog", table "dbo.product_details", column 'product_id' ".......
i have 2 tables, product_details and purchase_details.....

CREATE TABLE product_details
(
product_id int identity(1,1) not null,
product_name varchar(500),
product_catagory varchar(100),
CONSTRAINT PK_product_details PRIMARY KEY(product_id)
)

CREATE TABLE purchase_details
(
Purchase_id int not null identity(1,1) ,
product_id int CONSTRAINT FK_product_details FOREIGN KEY REFERENCES product_details(product_id) ,
Product_Name varchar(500),
Product_Cost VARCHAR(500),
Product_Quantity varchar(500),
CONSTRAINT PK_Purchase_details PRIMARY KEY(Purchase_id)
)

when i was try to insert values in 'purchase_details' that error msg displayed.......i dont know wats the mistak there....


You really should start your own thread instead of jumping onto somebody else's. However, the issue here is you are trying to insert a row into purchase_details and the value in product_id does not exist in your product_details table.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1437441
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse