Sql 2005 database has a foriegn key constraint error

I have a database that keeps logging errors as a foriegn key constraint error. I'm an infastructure guy so sql is pretty much a mystery to me. i've attached the error, the customer says that the database is working but have concerns about the error. Can I get some help from you SQL guru's out there please?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There is an error in the database "SMS_AR_Report"

stating that you are trying to insert a value into the table "dbo.Topics" in the column 'topic_ID'.

This topic_ID is the foreign key (meaning that this ID has another table that it looks at to see if the number being put here exists in that other table, and if not cause this error).  So the insert statement it is inserting an ID in this field that does NOT exist in the other table.  

Unless I missed it, it does not tell me what table has the foreign key in it that needs to have the topic_id inserted into before the error will not work.

You need to look at this Foreign key in "Topics"  "FK_HST_SuspectData_Topics".   and this should give you the details you need.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DBAduck - Ben MillerPrincipal ConsultantCommented:
The concept is this:

You declare a Primary Key in the Primary table that is the parent.  Then in the child table that will have Foreign keys (related records to the Parent) you declare a Foreign Key constraint, that basically says, for every key in this child table (in your case Topic_ID) there must exist a Parent record with the same Topic_ID in the Parent Table (Primary table).

So I have this:
ParentTable (Topic_ID) declared as Primary Key
I insert Topic_ID 1000 into that table.

ChildTable (Topic_ID) declared as Foreign Key pointing to the Primary Key (PrimaryTable.Topic_ID)
I insert Topic_ID 1000 into that table, everything is OK.
I insert Topic_ID 1001 into that table, ERROR, there is no 1001 in Primary Key table, only 1000.

What this does is keep there from being Orphans in the Foreign Key table (Children without Parents) so that your data has integrity referentially.  This way I will never have to worry about the child table having rows that do not relate to the parent table.

Hope this makes sense.  So the long and the short of it is, the inserts that are happening on the Foreign Key table and throwing errors are because the Parent table does not contain that Topic_ID, therefore it is a violation.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.