Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created January 20, 2012 20:48
Show Gist options
  • Save bemasher/1649477 to your computer and use it in GitHub Desktop.
Save bemasher/1649477 to your computer and use it in GitHub Desktop.
SELECT DISTINCT 'DELETE FROM ' + a.TABLE_NAME + ' WHERE PrimaryKeyColumn IN (SELECT PrimaryKeyColumn FROM @WhatToDelete)'
FROM INFORMATION_SCHEMA.COLUMNS a
JOIN INFORMATION_SCHEMA.TABLES b ON a.TABLE_NAME = b.TABLE_NAME
WHERE COLUMN_NAME LIKE 'PrimaryKeyColumn' AND b.TABLE_TYPE = 'BASE TABLE'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment