Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I want to update a table named employee but I am getting an exception as there some other tables associated with it in a foreign key constratint.
How can i update the table, can anyone help me.
How can i drop foreign key constraint and then update the table and then again put the constraint.

thanks
Posted

No you should not be dropping the foreign key.
Instead have a look at the CASCADE option[^].
Alter your table structure to use it.
 
Share this answer
 
Comments
RaisKazi 31-Aug-11 8:57am    
Agree 5. DB Constraints are not which can be used like Transactions.
Give thought to Abhinav's advice - but if you go ahead this should do it:

ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol;


Here's an actual example that I have used:

ALTER TABLE VendaTic.RoleMaster DROP FOREIGN KEY Feature_Code;
 
Share this answer
 
Comments
RaisKazi 31-Aug-11 8:57am    
Should help. 5!
Hello Dear,

What ever you are asking that is not possible. According to you the employee table is associated with another table by a foreign key. If you don't want another table reocord then do the following steps

1. right Click on the employee table and select modify. Then table will open with its column and datatypes. selct the column which is the foreign key.
2.Right click on that column and select relaionship.
3.One window will open where you select insert and update specification and selct the update rule then select no action from the dropdown.
4. Now your table will allow you to update.

Hope this will help you. If not then query again.
 
Share this answer
 
v2
Comments
[no name] 31-Aug-11 8:10am    
Thanks Sir for replying.
But won't it raise an error this way?
I want to update the column which is set as foreign keys for others so how can i update this column and other column in other tables at the same time?
Thanks a lot guys for replying. Your replies are really helpfull, for everyone, if you are struck in such condition, never try the approach i followed that is droping the foreign key and then updating the table and then adding the foreign keys, it will mess up the structure and will make your database unstable.
Whatever everyone replied, thats the right approach but for me its still little chaotic as I can't modify the table because of some restrictions.
Is there any other way of doing the same without modifying the table to make it cascade.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900