Common SQL statements
1. query data table names, fields, and field descriptions
SELECT t. [name] AS table name, c. [name] AS field name, cast (ep. [value] as nvarchar (200) AS [field description] FROM sys. tables AS t inner join sys. columns AS c ON t. object_id = c. object_id left join sys. extended_properties AS ep ON ep. major_id = c. object_id AND ep. minor_id = c. column_id WHERE ep. class = 1 AND t. name = 'tablename'
2. SQL user-defined functions and Recursion with (Note: The default with recursion level is 100)
ALTER function [dbo]. [fun_GetMemNewsGroupParentIDs] (@ newkgids nvarchar (500) returns @ t table (NewGrpID int, ParentID int) asbeginWITH T (SELECT NewGrpID, ParentID FROM MemNewsGroup WHERE charindex (', '+ ltrim (NewGrpID) +', '+ @ newkgids +', ')> 0 union all select. newGrpID,. parentID FROM MemNewsGroup as a join t as B ON. newGrpID = B. parentID) insert into @ t select distinct NewGrpID, ParentID from TRETURNend