Friday, September 26, 2014

Getting To Know That DB You Inherited (SQL Server)

Useful SQL queries to get to know that legacy db you are assigned:

select, count('count'
from sys.columns col
inner join sys.tables tab on col.object_id = tab.object_id
INNER JOIN sys.types t ON col.user_type_id = t.user_type_id
group by
order by 'count' desc

name count
datetime 36
int 32
char 32
decimal 24
varchar 19
sysname 1
varbinary 1

Actually, turns out the sysdiagrams table will mess up your numbers. Mostly you'll get an extra sysname and varbinary (and 3 extra int values).  So if you are using it to see which kind of types you have to contend with (as I was doing), know you can ignore those.

Also see:

No comments: