... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2008-01-09

SQL Server System-Generated Names

On SQL Server, the following query will list all SQL elements that have system-generated names (e.g. indexes, constraints):

select tab.name "table", obj.type "type", obj.name "name"
from (
  select null "type", null "name", null "tableId" where 1=0
  union select 'index', name, id from sysindexes where name not like '_WA_SYS%'
  union select 'primary key', name, parent_obj from sysobjects where xtype='PK'
  union select 'foreign key', name, parent_obj from sysobjects where xtype='F'
  union select 'check constraint', name, parent_obj from sysobjects where xtype='C'
  union select 'unique constraint', name, parent_obj from sysobjects where xtype='UQ'
  union select 'default constraint', name, parent_obj from sysobjects where xtype='D'
) obj
inner join sysobjects tab on (tab.id=obj.tableId)
where objectproperty(obj.tableId, 'isMsShipped')=0
and obj.name like '%\_\_%' escape '\'
order by tab.name, obj.type, obj.name

Blog Archive