Quantcast
Channel: CodeFari
Viewing all articles
Browse latest Browse all 265

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

$
0
0
There are many way to find tables without primary key one of them described below.


Select
   Table_CataLogasDB_NAME,
   Table_SchemaasTBL_SCHEMA,
   Table_NameasTBL_NAME     
from
   information_schema.tablesT    
where
   NotExists(
      Select
         1
      from
         information_Schema.Table_ConstraintsC    
      where
         Constraint_Type='PRIMARY KEY'    
         andC.Table_Name=T.Table_Name    
         andC.Table_Schema=T.Table_Schema
   )    
   andTable_Type='BASE TABLE'



 This query will fetch all tables’ information which do not have primary key.

Viewing all articles
Browse latest Browse all 265

Trending Articles