Tuesday, 8 January 2008

Investigating DB Designs...

Tables without Primary keys ;

SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName
    FROM sys.tables
    WHERE OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 0
   AND OBJECTPROPERTY(OBJECT_ID,'IsMSShipped') = 0
    ORDER BY SchemaName, TableName;



Tables without indexes ;

SELECT SCHEMA_NAME(schema_id) AS SchemaName,name AS TableName 
 FROM sys.tables 
 WHERE OBJECTPROPERTY(object_id,'IsIndexed') = 0 
   AND OBJECTPROPERTY(OBJECT_ID,'IsMSShipped') = 0
    ORDER BY SchemaName, TableName;

No comments: