Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I developing a new database,
The entity table contains [ID(Primary Key), Name, Date, Identity(Primary Key)].
The Child Tables as follows,
1. State [StateID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]
2. City [CityID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]
3. Street[StreetID(Primary Key & Foreign Key with Entity Table), Identity(Foreign Key with Entity Table)]

If i want to delete a particular ID in entity table, it should delete in entire child tables too. For me, The Entity Table contains more number of foreign key, so i can't able to use cascading function. Whether, while using more number of primary key and foreign key affected in the table. We can able to create an option of cascading? What may be the reason?





I having 1 Master Table and 5 Child table, the every child table among them and i gave "CASCADE" for delete function. If i connect all the child table to master table, and only 1 "CASCADE" only allowing. Kindly give me a solution to give more than one cascade
Posted
Updated 23-Dec-11 18:10pm
v2

Don't quite understand your question. A single table cannot have multiple primary keys. A primary key can be a composite key but that won't make foreign key constraints unusable.

If having a composite key is the problem, just define all the columns necessary to the primary key. However based on the field names they don't look like they would be composite.
 
Share this answer
 
Hi,

You are using referencing, when you define foreign key then there there is one property to be set, cascading deletion, set it to true. Your problem will be solve.
 
Share this answer
 
Comments
Member 7744835 24-Dec-11 0:14am    
I maintaining 1 MASTER and 5 CHILD, While all child table related to master table, it allowing only one CASCADE. I want to set CASCADE function for all Child table.
Hi,

Cascading delete is possible in your scenario as well. if you are not able to do that then there can be other workaround,

1) Make your all operation on table should be through Stored procedure.
2) do not allow direct access to table.
3) create transaction inside stored procedure
4) within transaction call delete operation for your child table.

but use above scenario only if you are unable to create cascade delete on your foreign key.

Hope this will help you,

thanks
-amit.
 
Share this answer
 
yeah Cascading delete is the solution that u want but u should use it carefully
 
Share this answer
 

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