loop through all tables and delete records

后端 未结 4 1610
借酒劲吻你
借酒劲吻你 2021-01-23 06:20

I\'m new to MsSql and I\'m not sure if this can be done but I figured I\'d ask before I want on my way with the current process..

I need to create a script that loops th

4条回答
  •  甜味超标
    2021-01-23 06:54

    You could run a query like this:

    SELECT 'DELETE FROM [' + s.name + '].[' + t.name + '] WHERE CorporationId = ''52D3AEFE-8EBD-4669-8096-4596FE83BB36'''
    FROM sys.columns c
        inner join sys.tables t
            ON t.object_id= c.object_id
        inner join sys.schemas s
            ON s.schema_id = t.schema_id
    where c.name = 'CorporationId'
    

    and then either copy and paste the results into a new query window and execute the new query or iterate over the results with a cursor and execute each result with the exec statement.

提交回复
热议问题