Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
i have 3 tables namely transemployee, refDesignation and refEmployeetype table. the transemployee table is the main table where i have columns like empid,firstname,middlename,lastname,entrepriseid,mailid,designationId,employeetypeid,createdon,modifiedon and isactive columns.
 
the other tables have designationid,designation(refdesignation table) and employeetupeid and employeetype..
 
in the trans emplyee table empid is d primary key and in refemployeetype and refdesignation table designationid and employeetypeid is the primary key
 
these act as foreign keys in transemployee table.
 
now if i ngive a insert query like this i get the following error:
 
INSERT INTO [UserManagementDB].[dbo].[TransEmployee]
           ([FirstName]
           ,[MiddleName]
           ,[LastName]
           ,[EntrepriseId]
           ,[MailId]
           ,[DesignationId]
           ,[EmployeeTypeId]
           ,[CreatedOn]
           ,[ModifiedOn]
           ,[IsActive])
     VALUES
           ('abi','raman','shankar','abi.r.shank','abi..shank@accenture.com',1,2,12/11/2012,13/11/2012,0)
GO
 
i get hte error as The INSERT statement conflicted with the FOREIGN KEY constraint "FK_TransEmployee_RefDesignation". The conflict occurred in database "UserManagementDB", table "dbo.RefDesignation", column 'DesignationId'.
Posted 12-Dec-12 23:56pm
Edited 13-Dec-12 0:27am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
First insert designationid in designation table and employeetupeid in employeetypetable then insert the value to TransEmployee table with same designationid & employeetypeid
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

HI,
 
This error occurred due to the empty record in the parent table whose ID is foreign keyed in the TransEmployee table.
 
So 1st of all make an entry in the parent tables (designation, employeetype ). Then only the foreign key will be available to your 3rd table (TransEmployee).
 
Thanks
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100