What I learnt Today
Monday, November 30, 2009
I thought of creating a series of what I learnt today. I feel almost everyday I learn something new and it gets slipped somewhere at the back of mind if I don't recall it. So its better to post it so that it will be a sort of revision for me and would be helpful to others. So I'll post my day to day learning under this post.
Today when I was working on Merging 2 databases and making them one, we had to define new constraints and keys . While defining new keys we found the following type of error coming.
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK__Grid__Page_ID__523BA32C". The conflict occurred in database "STATSONLINE", table "dbo.Page", column 'Page_ID'.
This error was caused when I ran the following query to give foreign key constraint.
ALTER TABLE Grid ADD FOREIGN KEY (Page_id ) REFERENCES Page(Page_Id)
After looking at the error one would guess that query is trying to define some foriegn key on the table 'Grid' which is already there and hence not allowing to overwrite that. At least I did think that way and started serching for all the Keys defined on the table. To my surprise there wasn't any such constraint define. Finally I concluded that It happens when this constraint can not be defined on the table because of inconsistent data. I had many grid records defined with the pages that are not there in page table. So it violates the basic requirement of foreign key.
About FK__Grid__Page_ID__523BA32C I feel it is the in memory name that server has given temporarily and then it checks all the records against this constraint and if it doesn't meet the criteria it throws aforesaid exception.