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 2000 Forums
 Transact-SQL (2000)
 Need advice making a big job simple

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-07-11 : 11:17:39
Steven writes "I have a single client's data I need to extract from a larger database cluster. The plan of action is to remove everything from the database EXCEPT for the client data. If the data is not explicitly linked to the client, it can stay(unless it contains another client's ID). There are a total of about 228 tables. Most of these tables have a ID that directly links to the client. My question is, I need to write a query or SP that goes through each table and deletes everything that doesn't have an ID of the specific client. It seems really easy, I just need to have a parameter that passes the string name of the table to a delete statement. I just don't know how to make the parameter change to the next table's name. Any help would be appreciated as it will save hours of manual work. Thanks!

guru in training"

nr
SQLTeam MVY

12543 Posts

Posted - 2006-07-11 : 11:48:05

create table #a (t varchar(128)
insert #a select 'tbl1' ......

declare @sql varchar(1000)
declare @t varchar(128)
select @t = ''
while @y < (select max(t) from #a
begin
select @t = min(t) from #a where t > @t
select @sql = 'delete ' + @t + ' where clientid = 666'
exec (@sql)
end



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -