Just Code‎ > ‎

TSQL - Find tables that is missing some kind of contraint

posted Jun 21, 2011, 7:37 AM by Peter Henell
SELECT *
FROM 
    INFORMATION_SCHEMA.tables  iss
LEFT OUTER JOIN    
    sys.key_constraints
    ON iss.TABLE_NAME = OBJECT_NAME(parent_object_id) AND iss.TABLE_SCHEMA = SCHEMA_NAME(schema_id) AND type = 'UQ'
WHERE 
    name IS NULL    
    
ORDER BY TABLE_SCHEMA, TABLE_NAME
Comments