From: MaMo on
Hello,

In a stored procedure i want to delete data from multiple tables.

Now i am doing this in my stored procedure:

DELETE FROM table1


From: Uri Dimant on
See Dan Guzman's script to do that

DECLARE @TruncateStatement nvarchar(4000)
DECLARE TruncateStatements CURSOR LOCAL FAST_FORWARD
FOR
SELECT
N'TRUNCATE TABLE ' +
QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE = 'BASE TABLE' AND
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
OPEN TruncateStatements
WHILE 1 = 1
BEGIN
FETCH NEXT FROM TruncateStatements INTO @TruncateStatement
IF @@FETCH_STATUS <> 0 BREAK
RAISERROR (@TruncateStatement, 0, 1) WITH NOWAIT
PRINT (@TruncateStatement
-- EXEC(@TruncateStatement)
END
CLOSE TruncateStatements
DEALLOCATE TruncateStatements




"MaMo" <afraidofspam(a)sorry.com> wrote in message
news:222cb$4b7167d7$d969db07$16824(a)cache90.multikabel.net...
> Hello,
>
> In a stored procedure i want to delete data from multiple tables.
>
> Now i am doing this in my stored procedure:
>
> DELETE FROM table1
>
> DELETE FROM table2
>
> DELETE FROM table3
>
> DELETE FROM table4
>
> ... and so on
>
> Is it possible to do this in a more elegenat manner like holding the table
> names in some kind of array or variable and use a cursor or something to
> do de deletion?
>
> Any help would be very appreciated!!!
>
> Marcel
>
>


From: --CELKO-- on
>> Is it possible to do this in a more elegenat manner like holding the table names in some kind of array or variable and use a cursor or something to do deletion? <<

REFERENCES .. ON DELETE CASCADE declarative referential action clause
instead of procedural code.
From: Uri Dimant on
"--CELKO--"
I have met one client when he implement REFERENCES .. ON DELETE CASCADE on
huge tables and it caused terrible locking on the system


"--CELKO--" <jcelko212(a)earthlink.net> wrote in message
news:cc2095ce-7ede-43d1-a270-8f63aafa9a15(a)d37g2000yqa.googlegroups.com...
>>> Is it possible to do this in a more elegenat manner like holding the
>>> table names in some kind of array or variable and use a cursor or
>>> something to do deletion? <<
>
> REFERENCES .. ON DELETE CASCADE declarative referential action clause
> instead of procedural code.


From: TheSQLGuru on
My guess would be that that happened because the child key wasn't indexed.

--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"Uri Dimant" <urid(a)iscar.co.il> wrote in message
news:OSpaM1hqKHA.1800(a)TK2MSFTNGP02.phx.gbl...
>
> "--CELKO--"
> I have met one client when he implement REFERENCES .. ON DELETE CASCADE
> on huge tables and it caused terrible locking on the system
>
>
> "--CELKO--" <jcelko212(a)earthlink.net> wrote in message
> news:cc2095ce-7ede-43d1-a270-8f63aafa9a15(a)d37g2000yqa.googlegroups.com...
>>>> Is it possible to do this in a more elegenat manner like holding the
>>>> table names in some kind of array or variable and use a cursor or
>>>> something to do deletion? <<
>>
>> REFERENCES .. ON DELETE CASCADE declarative referential action clause
>> instead of procedural code.
>
>