I'm lookin for a query that could list missing PK and FK.

I modified [this query](https://richarddingwall.name/2008/12/21/find-missing-foreignprimary-keys-in-sql-server/) and I ended up with this code:

```
-- Find columns on tables with names like FooID or FooCode which should
-- be part of primary or foreign keys, but aren't.
SELECT t.name AS [Table], 
       c.name AS [Column], 
       a.total_pages / 128.00 AS Total_MB
FROM sys.tables t
     INNER JOIN sys.syscolumns c ON c.id = t.object_id               
     -- Join on foreign key columns        
     LEFT JOIN sys.foreign_key_columns fkc ON(fkc.parent_object_id = t.object_id
                                              AND c.colid = fkc.parent_column_id)
                                             OR (fkc.referenced_object_id = t.object_id
                                                 AND c.colid = fkc.referenced_column_id)                
     -- Join on primary key columns        
     LEFT JOIN sys.indexes i ON i.object_id = t.object_id
                                AND i.is_primary_key = 1
     LEFT JOIN sys.index_columns ic ON ic.object_id = t.object_id
                                       AND ic.index_id = i.index_id
                                       AND ic.column_id = c.colid
     INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID
                                    AND i.index_id = p.index_id
     INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE t.is_ms_shipped = 0
      AND (c.name LIKE '%ID'
           OR c.name LIKE '%Code')
      AND (fkc.constraint_object_id IS NULL 
           -- Not part of a foreign key                 
           AND ic.object_id IS NULL 
      -- Not part of a primary key        
      )
      AND (                
      -- Ignore some tables                
      t.name != 'sysdiagrams'
      AND t.name NOT LIKE '[_]%' 
      -- temp tables                
      AND t.name NOT LIKE '%temp%'
      AND t.name NOT LIKE '%Log%' 
      -- log tables                                
      -- Ignore some columns                
      AND c.name NOT IN('GLCode', 'EID', 'AID'))
     AND a.total_pages > 1.0
-- external keys        
ORDER BY t.name, 
         c.name;

```

My question is all about line 40: `AND a.total_pages > 1.0`

* If you comment out that line it will return you all missing PK and FK
* If you use that line the goal is to return only table which have size > 1MB

...but instead is returning also tables with size 0.085937

[![enter image description here](https://i.stack.imgur.com/wriRL.png)](https://i.stack.imgur.com/wriRL.png)