How to get all tables without primary key in SQL Server?


There are many ways to find tables without primary key one of them described below.


Select
   Table_CataLog as DB_NAME,
   Table_Schema as TBL_SCHEMA,
   Table_Name as TBL_NAME     
from
   information_schema.tables T    
where
   Not Exists(
      Select
         1
      from
         information_Schema.Table_Constraints C    
      where
         Constraint_Type='PRIMARY KEY'    
         and C.Table_Name=T.Table_Name    
         and C.Table_Schema=T.Table_Schema
   )    
   and Table_Type='BASE TABLE'



This query will fetch all the table's information which do not have the primary keys.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...