Skip to content

Instantly share code, notes, and snippets.

View ronmichael's full-sized avatar

Ron Michael Zettlemoyer ronmichael

View GitHub Profile
@ronmichael
ronmichael / allparents.sql
Created February 5, 2015 14:22
Return all parent records in SQL hierarchy
/*
if you have a table of rows with parent rows, this will return one row for each row and each of its parents.
thanks to http://stackoverflow.com/questions/13487006/use-sql-server-cte-to-return-all-parent-records.
*/
with items(uniqueid,parentid) as (
select uniqueid, uniqueid
from equipment
@ronmichael
ronmichael / missing-permissions.sql
Created March 13, 2015 22:47
Identify all MSSQL database objects with no defined permissions
select type_desc, name
from sys.objects o
left join sys.database_permissions p on p.major_id=o.object_id
where p.class is null
and type_desc not in ('SYSTEM_TABLE','INTERNAL_TABLE','SERVICE_QUEUE','SQL_TRIGGER','TYPE_TABLE')
and type_desc not like '%CONSTRAINT%'
order by type_desc, name
@ronmichael
ronmichael / tables_and_columns_view.sql
Created February 19, 2016 22:40
A view of all tables and columns
select
dbo.sysobjects.name TableName,
dbo.syscolumns.name ColumnName,
dbo.systypes.name as Type
from dbo.sysobjects
join dbo.syscolumns on dbo.syscolumns.id = dbo.sysobjects.id
join dbo.systypes on dbo.systypes.xtype = dbo.syscolumns.xtype
where dbo.systypes.name != 'sysname'