database schema table

SELECT OBJECT_SCHEMA_NAME(T.[object_id],DB_ID()) AS [Schema], T.[name] AS [table_name], AC.[name] AS [column_name], TY.[name] AS system_data_type, AC.[max_length], AC.[precision], AC.[scale], AC.[is_nullable], AC.[is_ansi_padded], AC.[is_identity] FROM sys.tables AS T INNER JOIN sys.all_columns AC ON T.object_id = AC.object_id INNER JOIN sys.types TY ON AC.system_type_id = TY.system_type_id AND AC.user_type_id = TY.user_type_id ORDER BY…

Finding a hierarchy in SQL Server

thanks goes out to the book ‘SQL Cookbook’ – Lucky Chapter 13 Hierarchical Queries … with  x (tree,childid,depth) as  ( select  cast(name as varchar(500)), childid, 0 from vw_users_parent_children union  all select  cast(x.tree+’–>’+e.name as varchar(500)), e.childid, x.depth+1 from  vw_users_parent_children e, x where x.childid = e.children_id )…