use zefenggb go select name from sysobjects where xtype='U'
name 字段是对象名 xtype='U' u是用户表
用这个方面 功能说明:检索表(1)或视图(0),模糊检索用户表或者视图,查看表或者视图数据,按条件搜索 If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LookTableView]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) Drop procedure [dbo].[LookTableView] GO CREATE Procedure LookTableView @IfTable bit, @Table varchar(20)='', @SelectTable varchar(20)='', @Twhere varchar(100)='' as begin Declare @Sql varchar(2000) if @IFTable=1 begin if @SelectTable='' select Name from sysobjects where xtype='u' and name like '%'+@Table+'%' order by name else begin if @Twhere='' begin Set @Sql='select * from '+@SelectTable+'' end else begin Set @Sql='select * from '+@SelectTable+' where '+@Twhere+'' end exec(@Sql) end; end else if @IFTable=0 begin if @SelectTable='' select name from sysobjects where xtype='v' and category=0 and name like '%'+@Table+'%' order by name else begin if @Twhere='' begin Set @Sql='select * from '+@SelectTable+'' end else begin Set @Sql='select * from '+@SelectTable+' where '+@Twhere+'' end exec(@Sql) end; end end; GO
use zefenggb
go
select name from sysobjects where xtype='U'
xtype='U' u是用户表
功能说明:检索表(1)或视图(0),模糊检索用户表或者视图,查看表或者视图数据,按条件搜索
If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LookTableView]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
Drop procedure [dbo].[LookTableView]
GO
CREATE Procedure LookTableView
@IfTable bit,
@Table varchar(20)='',
@SelectTable varchar(20)='',
@Twhere varchar(100)=''
as
begin
Declare @Sql varchar(2000)
if @IFTable=1
begin
if @SelectTable=''
select Name from sysobjects where xtype='u' and name like '%'+@Table+'%' order by name
else
begin
if @Twhere=''
begin
Set @Sql='select * from '+@SelectTable+''
end
else
begin
Set @Sql='select * from '+@SelectTable+' where '+@Twhere+''
end
exec(@Sql)
end;
end
else if @IFTable=0
begin
if @SelectTable=''
select name from sysobjects where xtype='v' and category=0 and name like '%'+@Table+'%' order by name
else
begin
if @Twhere=''
begin
Set @Sql='select * from '+@SelectTable+''
end
else
begin
Set @Sql='select * from '+@SelectTable+' where '+@Twhere+''
end
exec(@Sql)
end;
end
end;
GO