In SQL Server 2005, can I do a cascade delete without setting the property on my tables?

前端 未结 13 1460
心在旅途
心在旅途 2020-12-12 17:02

I have a database full of customer data. It\'s so big that it\'s really cumbersome to operate on, and I\'d rather just slim it down to 10% of the customers, which is plenty

相关标签:
13条回答
  • 2020-12-12 17:52

    after select you have to build and execute the actual delete

    declare @deleteSql nvarchar(1200)
    declare delete_cursor cursor for
    select table_name, criteria 
    from @to_delete
    order by id desc
    
    open delete_cursor
    
    fetch next from delete_cursor
    into @table_name, @criteria
    
    while @@fetch_status = 0
    begin
     select @deleteSql = 'delete from ' + @table_name + ' where ' + @criteria
     --print @deleteSql
    -- exec sp_execute @deleteSql
    EXEC SP_EXECUTESQL @deleteSql
    
     fetch next from delete_cursor
     into @table_name, @criteria
    end
    close delete_cursor
    deallocate delete_cursor
    
    0 讨论(0)
提交回复
热议问题