The answer, in SQL Server 2008, is quite a few. A day or so ago Paul Randall tweeted about the lack of consistency within the column naming in system objects that reference databases (id or name). It got me to thinking about the ones I knew which naturally led to being bothered that there might be others I don't know about (sometimes I really wish I could turn that off, oh well).
So to satisfy my curiosity (and hopefully enlighten/entertain you) here is the path I took to get the answer.
First, query the catalog view sys.all_columns for columns containing db or database in their names.
SELECT c.name AS ColumnName
FROM sys.all_columns AS c
INNER JOIN sys.all_objects AS o ON o.[object_id] = c.[object_id]
WHERE c.name LIKE '%db%' OR c.name LIKE '%database%'
GROUP BY c.name;
After a quick look through those results I boiled it down to a meaningful list and went back to sys.all_columns. The query below returns 65 rows for my instance.
SELECT c.name AS ColumnName
,SCHEMA_NAME(o.[schema_id]) AS SchemaName
,o.name AS ObjectName
,o.type_desc
FROM sys.all_columns AS c
INNER JOIN sys.all_objects AS o ON o.[object_id] = c.[object_id]
WHERE c.name IN(
'database'
,'Database Name'
,'database_id'
,'database_name'
,'DatabaseID'
,'DatabaseName'
,'db_id'
,'db_name'
,'dbid'
,'dbname'
,'Master DBID'
,'orig_db'
,'referenced_database_name'
,'resource_database_id'
,'SourceDatabaseID'
)
ORDER BY ColumnName
,SchemaName
,ObjectName;
There were a couple I had forgotten about but most items are DMVs. Still some fun detail to have in the back of your head for the next time you need it. Or just remember this blog post. Either way. :)
be128191-b32d-4a86-9bc1-bff05d30b5e3|2|5.0