Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Stored Procedure to delete records btach wisecommt

Author  Topic 

rahulm_32003
Starting Member

7 Posts

Posted - 2012-09-05 : 21:42:09
I have bunch of tables contains huge number records. All the tables are referring a primary key of table T1.Now.I have to write a stored procedure to delete the records in batches.I am new to SQL server programming .Please help me in writing this stored procedure

Scenario:

T1---primary key x1
T2- referential x1
T3-referential x1
T4-referential x1

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-05 : 21:43:55
why do you need to do it in batches? does it have something to do with log space etc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rahulm_32003
Starting Member

7 Posts

Posted - 2012-09-05 : 21:52:03
when there is huge number of records its taking too much time.If we do it batch commits even if forcefully kill the process we dont lose everything except the last batch
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-05 : 22:07:31
ok..makes sense then. do you've primary key in each of tables? are they related to each other by means of fk?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rahulm_32003
Starting Member

7 Posts

Posted - 2012-09-06 : 00:18:04
Yes.Some tables have primary keys but most of them are reatled to each other by means of table T1 primary key
Go to Top of Page
   

- Advertisement -