外键冲突 [英] foreign key conflict
问题描述
我有3个表,即transemployee,refDesignation和refEmployeetype表。 transemployee表是主表,其中我有像empid,firstname,middlename,lastname,entrepriseid,mailid,designationId,employeetypeid,createdon,modifiedon和isactive columns这样的列。
其他表格中有指定名称,指定(refdesignation table)和employeetupeid and employeetype ..
$ c $ b在trans emplyee表中,empid是d主键,在refemployeetype和refdesignation表中specifiedid和employeetypeid是主键
这些在transemployee表中作为外键。
现在如果我发现这样的插入查询我收到以下错误:
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得到错误,因为INSERT语句与FOREIGN KEY约束FK_TransEmployee_RefDesignation冲突。冲突发生在数据库UserManagementDB,表dbo.RefDesignation,列''DesignationId''。
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''.
推荐答案
首先在指定表中插入specifiedid,在employetyypetable中插入employeetupeid,然后将值插入TransEmployee表,并使用相同的名称和employeesetypeid
Hi,
First insert designationid in designation table and employeetupeid in employeetypetable then insert the value to TransEmployee table with same designationid & employeetypeid
HI,
发生此错误的原因是父表中的空记录,其ID在TransEmployee表中是外键。
因此,首先在父表中创建一个条目(指定,employeesetype)。然后只有外键可用于您的第3个表(TransEmployee)。
谢谢
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
这篇关于外键冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!