delete related records

In my database i have a table that contains topics and it is related to
another table which contains subtopics. What i have to do is delete a record
in the topics but i allso have to delete the related records in the sub
topics (as they are related). Is there a easier way to do this then having
to first delete the subtopics and then delete the topics records?
fmatosic [ Mo, 21 November 2005 19:04 ] [ ID #1067422 ]

Re: delete related records

polilop wrote:
> In my database i have a table that contains topics and it is related to
> another table which contains subtopics. What i have to do is delete a record
> in the topics but i allso have to delete the related records in the sub
> topics (as they are related). Is there a easier way to do this then having
> to first delete the subtopics and then delete the topics records?

Use foreign keys to enforce referential integrity, if your DBMS supports
this.

MC
The Mighty Chaffinch [ Mo, 21 November 2005 19:08 ] [ ID #1067423 ]

Re: delete related records

They use foreign keys to enforce referential integrity, thats why i cannot
delete a record from table topics if it has a record in the table subtopic ,
becouse subtopic contains the foreign key topics. But what i have to do is
delete a record from topics table and allso if it has a subtopic, delete it
allso. Is there a way to delete them both without having to delete the
record from the subtopic and then delete the related topic record???



"Mighty Chaffinch" <MightyChaffinch [at] hotmail.com> wrote in message
news:%232xejas7FHA.2384 [at] TK2MSFTNGP12.phx.gbl...
> polilop wrote:
>> In my database i have a table that contains topics and it is related to
>> another table which contains subtopics. What i have to do is delete a
>> record in the topics but i allso have to delete the related records in
>> the sub topics (as they are related). Is there a easier way to do this
>> then having to first delete the subtopics and then delete the topics
>> records?
>
> Use foreign keys to enforce referential integrity, if your DBMS supports
> this.
>
> MC
fmatosic [ Mo, 21 November 2005 21:05 ] [ ID #1067424 ]

Re: delete related records

Set up the relationships to do Cascading Deletes. But, be careful.

Bob Lehmann

"polilop" <fmatosic [at] inet.hr> wrote in message
news:ejkgmbt7FHA.1188 [at] TK2MSFTNGP12.phx.gbl...
> They use foreign keys to enforce referential integrity, thats why i cannot
> delete a record from table topics if it has a record in the table subtopic
,
> becouse subtopic contains the foreign key topics. But what i have to do is
> delete a record from topics table and allso if it has a subtopic, delete
it
> allso. Is there a way to delete them both without having to delete the
> record from the subtopic and then delete the related topic record???
>
>
>
> "Mighty Chaffinch" <MightyChaffinch [at] hotmail.com> wrote in message
> news:%232xejas7FHA.2384 [at] TK2MSFTNGP12.phx.gbl...
> > polilop wrote:
> >> In my database i have a table that contains topics and it is related to
> >> another table which contains subtopics. What i have to do is delete a
> >> record in the topics but i allso have to delete the related records in
> >> the sub topics (as they are related). Is there a easier way to do this
> >> then having to first delete the subtopics and then delete the topics
> >> records?
> >
> > Use foreign keys to enforce referential integrity, if your DBMS supports
> > this.
> >
> > MC
>
>
Bob Lehmann [ Di, 22 November 2005 01:53 ] [ ID #1069052 ]
Webserver » microsoft.public.inetserver.asp.db » delete related records

Vorheriges Thema: I'm facing this problem in PHP
Nächstes Thema: I'm facing this problem in PHP