The INSERT statement conflicted with the FOREIGN KEY?

Posted by Pramodmca09 under Sql Server on 4/22/2010 | Views : 6771 | Status : [Member] | Replies : 1
I have two table is a database named
=> Region(RegionID int PK, RegionName, RegionDesc) and

create table Region (RegionID int not null primary key, RegionName varchar(30) not null, RegionDesc varchar(100) null);

AND

=> ArchSite(SiteID int PK,RegionID int FK, SiteName,SiteDesc,SiteStreet,SiteLandmark,SiteCity,SitePincode,SiteSteate,SiteCountry )


create table ArchSite1
(SiteID int not null primary key, RegionID int not null
foreign key references Region(RegionID),
SiteName varchar(20) not null, SiteDesc varchar(200)
, SiteStreet varchar(50), SiteLandmark varchar(100), SiteCity varchar(30) not null, SitePincode int not null
, SiteState varchar(30) not null, SiteCountry varchar(30) not null)
I have inserted 10 records in Region Table having primary key 1,2,3...10
now when I try to insert record in Site Table having records like


insert into ArchSite values(1,1,'Ganga Pallaace','Row houses and banglows',East Road', 'Bus Stop',' Chenni ', 411010 ,' Gujrat ','England');
I;m getting error like .
.
.
.
.
.Msg 547, Level 16, State 0, Line 2
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__ArchSite__Regio__02084FDA". The conflict occurred in database "eCMS", table "dbo.Region", column 'RegionID'.
The statement has been terminated.
....
Please Help me out...Thank u in advance




Responses

Posted by: Pandians on: 4/23/2010 [Member] [MVP] Silver

Up
0
Down
Hi

Greetings

1. Check the value 1 is there in Parent table(Region - RegionID)

2. Check how many tables being referred by the Child table (ArchSite), Only Region table or some other table Using the script given below...

SELECT OBJECT_NAME(K.Parent_OBJECT_ID) 'Table Name',
K.[Name] 'Constraint Name',
OBJECT_NAME(K.Referenced_OBJECT_ID) 'Parent Table',COL_NAME(K.Referenced_OBJECT_ID,C.Colid) 'Column Name' FROM SYS.FOREIGN_KEYS K JOIN SYS.SYSCONSTRAINTS C
ON (K.Parent_OBJECT_ID = C.ID AND k.[object_id] = C.Constid)
WHERE K.Parent_OBJECT_ID = OBJECT_ID('ArchSite')

Cheers


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Pramodmca09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response