李磊专栏

他山之石 可以攻玉
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

通过SQL语句模糊查找对应

Posted on 2016-10-13 11:54  李磊(leige)  阅读(143)  评论(0)    收藏  举报

create proc [dbo].[get_user_object](  @StrName varchar(100),  @Type varchar(10) = 'all' ) as begin  set nocount on  --查询非用户表,即函数、存储过程、视图、约束等等。  select schema_name(schema_id) as [schema],*  from sys.objects  where object_id in(   select id from syscomments   where [text] like '%'+@StrName+'%'     and patindex('%201[0-9]%',[name]) = 0 --排除名字中包含年份的备份数据库对象  ) and (@type = 'all' or [type] = @type)

 union all  --查询用户自定表。  select schema_name(schema_id) as [schema],*  from sys.objects  where [name] like '%'+@StrName+'%'   and patindex('%201[0-9]%',[name]) = 0 --排除名字中包含年份的备份数据库对象   and [type] ='U' and ( @type='all' or @type = 'U')

 order by [name]  set nocount off end

 

调用方法: [dbo].[uspGetDepends] '订单'