I had a specific relational database with different tables. what I wanted to do is actually copy two tables from different databases located on a different server into my database with the help of the Microsoft SQL Server Management Studio 2017 export function. new tables have been imported into my current database. However, the problem is that the tables that were exported from the other database in mine do not have primary and foreign keys. So, what I did, I deleted the old tables from my current database and I am now working on adding primary and foreign keys to freshly copied ones.
The problem is that I was able to create the primary keys without any problem, however, when I tried to create the foreign key to the second table to bind it to the first table, I had this mistake:
The ALTER TABLE statement conflicts with the FOREIGN KEY constraint
I know the reason for the mistake because of the unparalleled number of items in my first and second tables. I ran this query:
select UUT_RESULT in STEP_RESULT WHERE UUT_RESULT NOT IN (SELECT UUT_RESULT ID)
I could see that there are 883 entries in my second table does not fit in the first table.
How can I solve this problem? I can not clean the tables because they contain 15 million entries. Is there any way to remove these 883 from the second table and match the two?