Q:

Sql Server 2008 Create Foreign Key Manually

I have inherited an old database which wasn't designed very well. It is a Sql Server 2008 database which is missing quite a lot of Foreign Key relationships. Below shows two of the tables, and I am trying to manually create a FK relationship between dbo.app_status.status_id and dbo.app_additional_info.application_id

I am using SQL Server Management Studio when trying to create the relationship using the query below
USE myDatabase; 
GO ALTER TABLE dbo.app_additional_info 
ADD CONSTRAINT FK_AddInfo_AppStatus FOREIGN KEY (application_id) 
    REFERENCES dbo.app_status (status_id) 
    ON DELETE CASCADE
    ON UPDATE CASCADE ; 
GO

However, I receive this error when I run the query

The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
  "FK_AddInfo_AppStatus". The conflict occurred in database
  "myDatabase", table "dbo.app_status", column 'status_id'.

I am wondering if the query is failing because each table already contains approximately 130,000 records?
Please help.
Thanks.

A:

The error is occuring because there is a value in dbo.app_additional_info.application_ID that is not in dbo.app_Status.Status_ID. Unless the naming convention is seriously messed up you are trying to add a relationship to unrelated columns, why would application_ID reference status_ID? 
I expect that dbo.App_Additional_Info.Application_ID should be referencing dbo.Application.Application_ID (Guessing at the table and column names slightly) so you would want this:
USE MyDatabase
GO
ALTER TABLE dbo.App_Additional_Info
ADD CONSTRAINT FK_App_Additional_Info_Application_ID (Application_ID)
    REFERENCES dbo.Application (Application_ID)
    ON DELETE CASCADE
    ON UPDATE CASCADE;

