I was checking a third party server, and I needed to find if
there were tables without primary keys. This is important to
know, not only because the lack of primary keys affects
performance and data accuracy in general, but also because in
row-based replication performance can degrade
beyond belief when updating tables without primary keys.Anyway, I
did not remember off the bat any method to get this information
from a server with thousands of tables, and thus I went to find a
solution on my own.My first instinct called for using the
COLUMNS table from the
INFORMATIOn_SCHEMA, and so I came up with this
query, where I sum the number of columns that are inside either a
PRIMARY or UNIQUE key and filter only the ones where such sum is
zero (i.e. no primary or unique keys):
[Read more]
select
…