[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Delete row triggers drop table

scota

3/29/2007 8:09:00 PM

I have a table called Calendar with a primary key on Cal_Num.

If I delete a row(s), I want a trigger that would delete a
corresponding table(s) within the database (i.e. delete Cal_Num=311
from Calendar and then tblEvents311 will be dropped).

If this can be done, how would I write the trigger?

2 Answers

David Portas

3/29/2007 8:45:00 PM

0

On 29 Mar, 21:08, s...@metrohealth.org wrote:
> I have a table called Calendar with a primary key on Cal_Num.
>
> If I delete a row(s), I want a trigger that would delete a
> corresponding table(s) within the database (i.e. delete Cal_Num=311
> from Calendar and then tblEvents311 will be dropped).
>
> If this can be done, how would I write the trigger?

I definitely would not recommend it.

It seems like you have an incredibly silly design for a database. Why
not just combine the Events data into one table? If you really must
keep creating and dropping tables then I would do it as part of a
scheduled clean-up task rather than in a runtime transaction.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/librar...(en-US,SQL.90).aspx
--

scota

3/30/2007 2:29:00 PM

0

On Mar 29, 4:44 pm, "David Portas"
<REMOVE_BEFORE_REPLYING_dpor...@acm.org> wrote:
> On 29 Mar, 21:08, s...@metrohealth.org wrote:
>
> > I have atablecalled Calendar with a primary key on Cal_Num.
>
> > If I delete a row(s), I want atriggerthat would delete a
> > correspondingtable(s) within the database (i.e. delete Cal_Num=311
> > from Calendar and then tblEvents311 will be dropped).
>
> > If this can be done, how would I write thetrigger?
>
> I definitely would not recommend it.
>
> It seems like you have an incredibly silly design for a database. Why
> not just combine the Events data into onetable? If you really must
> keep creating and dropping tables then I would do it as part of a
> scheduled clean-up task rather than in a runtime transaction.
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATETABLEand INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:http://msdn2.microsoft.com/librar...(en-US,SQL.90).aspx
> --

David, you are absolutely correct. I did not design this database but
have been working with it in it's current state until the app can be
rewritten. A lot of data could be lost if I were to delete a record
by mistake.