SQL Server Performance Forum – Threads Archive
FK error
I get the following error when trying to add a FK reference: ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint ‘FK_tblTrading_Indices_Constituents_tblTrading_Indices’. The conflict occurred in database ‘database2’, table ‘tblTrading_Indices’, column ‘Index_Code’. I checked. That FK does not exists. Just to be safe I tried dropping it and no luck. I added a UNIQUE constraint on Index_Code in the table being referenced. Both Index_Code cols in each table are same datatype. Suggestions are appreciated.No replies? Can someone help? Thanks.
quote:Originally posted by photura
I get the following error when trying to add a FK reference:
ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint ‘FK_tblTrading_Indices_Constituents_tblTrading_Indices’. The conflict occurred in database ‘database2’, table ‘tblTrading_Indices’, column ‘Index_Code’.
I checked. That FK does not exists. Just to be safe I tried dropping it and no luck.
I added a UNIQUE constraint on Index_Code in the table being referenced. Both Index_Code cols in each table are same datatype.
Suggestions are appreciated.
Are you looking at just two tables? There may be a third table involved. This will tell you the name of the table on which your constraint FK_tblTrading_Indices_Constituents_tblTrading_Indices is defined: SELECT OBJECT_NAME(s.id)
FROM dbo.sysconstraints s
WHERE s.constid =
OBJECT_ID(‘FK_tblTrading_Indices_Constituents_tblTrading_Indices’)
Also run sp_fkeys ‘parentTable’ to know all child tables Madhivanan Failing to plan is Planning to fail
<pre id="code"><font face="courier" size="2" id="code"><br /><b>sp_</b>fkeys ‘parentTable'<br /></font id="code"></pre id="code"><br />[<img src=’/community/emoticons/emotion-1.gif’ alt=’
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
I just edited the reply Frank. As usual you are faster [<img src=’/community/emoticons/emotion-1.gif’ alt=’
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
I really like the RSS feed. [<img src=’/community/emoticons/emotion-1.gif’ alt=’
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by FrankKalis</i><br /><br />I really like the RSS feed. [<img src=’/community/emoticons/emotion-1.gif’ alt=’
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
I don’t have any idea.<br /><br />I ran your statement below and it returned a blank row.<br /><br />I also ran the sp twice with each table name as the parent table and it also returned a blank row.<br /><br />Then I tried running the FK statement again:<br /><br />ALTER TABLE tblTrading_Indices_Constituents<br />ADD CONSTRAINT FK_tblTrading_Indices_Constituents_tblTrading_Indices FOREIGN KEY (Index_Code) <br />REFERENCES tblTrading_Indices (Index_Code)<br /><br />and it still returns the same error:<br /><br />ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint ‘FK_tblTrading_Indices_Constituents_tblTrading_Indices’. The conflict occurred in database ‘dfasys2’, table ‘tblTrading_Indices’, column ‘Index_Code’.<br /><br /><br />Help! <img src=’/community/emoticons/emotion-1.gif’ alt=’
![Smile :) :)](styles/default/xenforo/smilies/smile.png)
did you check if all the data in the child is in the parent table? May the Almighty God bless us all!
www.empoweredinformation.com
]]>