473,508 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Delete

92 New Member
Hi

Anyone suggest me a query for, if i delete master table values it must delete all its dependent table.

ie.
I hv 2 tables. Fields as

Master table.
1. MID
2. Name

Child Table
1.MID
2.Child Name.

if i delete Master table record. it must automatically delete its child table record.
how can i do this using SQL query.

Suggest me plz.

Thanks in Advance.
May 12 '08 #1
3 1476
Delerna
1,134 Recognized Expert Top Contributor
1) you need to set the primary key on the maser table on field MID
2) I think you will need to add a field to the child table called ChildID
and then set the primary key to both MID and ChildID on that table
3) Create a relationships diagram with those two table in it
4) Connect the two tables on the MID field and turn on "Cascade delete related records"
May 12 '08 #2
Limno
92 New Member
1) you need to set the primary key on the maser table on field MID
2) I think you will need to add a field to the child table called ChildID
and then set the primary key to both MID and ChildID on that table
3) Create a relationships diagram with those two table in it
4) Connect the two tables on the MID field and turn on "Cascade delete related records"


Thanks 4 replying me

why i should create ChildID. with that MID itself i wnt to delete it. Can u suggest me the query for this delete processing.

Explain me clearly with query plz
May 12 '08 #3
Delerna
1,134 Recognized Expert Top Contributor
OK i just did a test and you don't actually need to add the field or set the primary key on the child table

So this is now what you need to do
1) you need to set the primary key on the maser table on field MID
2) Create a relationships diagram with those two table in it
3) Connect the two tables on the MID field and turn on "Cascade delete related records"

The delete query will be just a standard delete query. The query is not important to the discussion here.

The thing that makes it work is the "cascade delete related fields" option in the relationships diagram. When you delete a record from the master table any related records in the child table will automatically be deleted
May 12 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2568
by: Dave | last post by:
Hello all, In the code below, I see the following output: base::operator new(size_t, int) base::base() base::~base() base::operator delete(void *) In the case of an exception being thrown...
1
3828
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
3
9356
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
1
3873
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
2
2070
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
3
4633
by: silver360 | last post by:
Hello, I'm trying to create a basic Heap manager and i have some question about new/delete overloading. The following code give me this output : >> $./heap >> registered : 0x804d098 >>...
9
8147
by: rohits123 | last post by:
I have an overload delete operator as below ////////////////////////////////// void operator delete(void* mem,int head_type) { mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
10
2072
by: jeffjohnson_alpha | last post by:
We all know that a new-expression, foo* a = new foo() ; allocates memory for a single foo then calls foo::foo(). And we know that void* p = ::operator new(sizeof(foo)) ; allocates a...
15
4991
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
29
2222
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I remembered delete is implemented through operator overloading, but I am not quite clear. Could anyone recommend some links about how delete is implemented so that I can...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.