Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Not understanding foreign key error

$
0
0
Hello all, 
I have a problem that I think is a little odd. First off i have three tables one is considered main, one with data and another one to copy the data too. Now i know about forgien key error and having to have the same value in the main as in the other.
So now I have this query . 

ALTER TABLE [dbo].[forign]  WITH CHECK ADD  CONSTRAINT [FK_deposits_num] FOREIGN KEY([num])
REFERENCES [dbo].[main] ([num])

Now this breaks and doesnt create because of issues with this num key. However when i do this query.

select num from dbo.foreign
where not Exists ( select num from dbo.main)

I get 0 returned as in there are no records that dont match. So why does this run.
Thank u

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>