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
Here is a Sql Fiddle that proves the below query
You can get the tables from this query:
SELECT Name, IsChecked = 0
INTO #Tables
FROM sys.Tables
WHERE EXISTS
(
SELECT * FROM sys.columns
WHERE object_id = OBJECT_ID(sys.Tables.Name) AND sys.columns.Name = 'blah'
)
Then, you can create a dynamic query and execute it for the tables that you found
WHILE(SELECT COUNT(*) FROM #Tables WHERE IsChecked = 0) > 0
BEGIN
SELECT TOP 1 @TableName = Name FROM #Tables WHERE IsChecked = 0
SET @DeleteQuery = 'DELETE FROM ' + @TableName + ' WHERE CorporationID = ''' + @CorporationId + ''''
EXECUTE sp_executeSQL @DeleteQuery;
UPDATE #Tables SET IsChecked = 1 WHERE Name = @TableName
END