码迷,mamicode.com
首页 > 数据库 > 详细

常用的SQL语句

时间:2015-04-08 10:55:37      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:sql2008

1.查询数据表名称、字段、字段说明

SELECT 
t.[name] AS 表名,
c.[name] AS 字段名,
cast(ep.[value] as nvarchar(200)) AS [字段说明]  
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自定义函数和递归with(注意:with递归默认层级是:100)

ALTER function [dbo].[fun_GetMemNewsGroupParentIDs](@NewGrpIDs nvarchar(500))
returns @t table(NewGrpID int,ParentID int)
as
begin
WITH T AS  
(  
SELECT NewGrpID,ParentID FROM MemNewsGroup  
WHERE charindex(','+ltrim(NewGrpID)+',',','+@NewGrpIDs+',') > 0
UNION ALL  
SELECT A.NewGrpID,A.ParentID 
FROM MemNewsGroup AS A JOIN T AS B ON A.NewGrpID = B.ParentID
)
insert into @t select distinct NewGrpID,ParentID from T
RETURN
end

常用的SQL语句

标签:sql2008

原文地址:http://blog.csdn.net/jayzai/article/details/44937559

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!