May 31, 2009 at 10:41 pm
hi all,
Here is the issue between me and my team that can we do changes in foreign key ,,,please let me knw the ans and with speccified reason ...
as per of me i sd no we can make change in foreign key values as it is refering the primary key of one table which should be unique.
May 31, 2009 at 11:43 pm
Hi,
I am not able to fully understand the question but what ever I can here is the crux.
Q: We have 2 tables Table A & Table B.
Table A
======
i int PK,
J varchar(100)
Table B
======
i Int FK from Table A
K varchar(100)
We have below values in Tables.
Table A
======
1 , Hello
2 , Tata
3 , Bye
Table B
======
1 , Sir
2 , Mr James
3 , Bye Gomes
Can we make change to TABLE B and make value for row number 3 where
value for I is 3 to 4?
Answer: No we cannot do that reason we have Primary Key & Foreign
Key relation in this column between these 2 tables.
Values in Foreign Key can be null and can be duplicate but it will
not be out of the range from what we have in Primary Key.
There should be a value in Table on which we have Primary Key
and then it will be refered in Child Table where Foreign Key is
defined.
I Hope this will answer to your question. Let me know if I have understood it wrong.
Regards
GURSETHI
June 1, 2009 at 3:46 am
ya this is also my assumption but i waann to knw view of u people for that so only i asked
thaks for ur quick reply....
June 1, 2009 at 6:37 am
Let me rephrase the question to see if I understand.
Are you asking is it possible to put data into the foreign key that is not contained in the primary key of the related table? If that's correct, then no. You can't do that, nor would you want to. The very concept of relational integrity is that the data between the two related tables will be protected. This means that no child records can be added without the appropriate parent and no parent records can be deleted without first deleting the children. In other words, no orphan records from either side.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply