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

前端 未结 13 1471
心在旅途
心在旅途 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:50

    Kevin post is incomplete, his t-sql sp only prints the command, to execute these command, before last end add this

    DECLARE @commandText VARCHAR(8000)
            DECLARE curDeletes CURSOR FOR
                select 'delete from [' + table_name + '] where ' + criteria from @to_delete order by id desc
    
            OPEN curDeletes
            FETCH NEXT FROM curDeletes
            INTO
                @commandText
    
            WHILE(@@FETCH_STATUS=0)
            BEGIN
                EXEC (@commandText)
                FETCH NEXT FROM curDeletes INTO @commandText
            END
            CLOSE curDeletes
            DEALLOCATE curDeletes
    

提交回复
热议问题