重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
如果是结构名称或者是存储、视图里写的注释可以查询sys.sql_modules。如果是某张表里的具体值,只能自己写个存储去全库所有表字段查询,效率很低
创新互联服务项目包括红河网站建设、红河网站制作、红河网页制作以及红河网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,红河网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到红河省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
select tope(@size)*from(select * from table) as _table
where _table.id not in (select top(@size*@page)id from table)order by id
要查询字段的长度减去该字段将要查询字符替换为空后的长度 select len(字段名)-len(replace(字段名,要查询的字符,''))
可用存储过程,如查找库中所有表所有字段,包含“张三”的数据
declare @cloumns varchar(40)
declare @tablename varchar(40)
declare @str varchar(40)
declare @counts int
declare @sql nvarchar(2000)
declare MyCursor Cursor For
Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c
where a.id = b.id
and b.type = 'U'
and a.xtype=c.xtype
and c.name like '%char%'
set @str='张三'
Open MyCursor
Fetch next From MyCursor Into @cloumns,@tablename
While(@@Fetch_Status = 0)
Begin
set @sql='select @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ ''''
execute sp_executesql @sql,N'@tmp_counts int out',@counts out
if @counts0
begin
print '表名为:'+@tablename+',字段名为'+@cloumns
end
Fetch next From MyCursor Into @cloumns,@tablename
End
Close MyCursor
Deallocate MyCursor
以下为在SQL Server中查看某个表的字段信息的查询语句(以数据库Pubs的jobs表为例)
SELECT SysObjects.Name as TableName,
SysColumns.Name as ColumnsName,
SysTypes.Name as DateType,
SysColumns.Length as DateLength,
SysProperties.Value as Remark --列描述
FROM SysObjects,
SysTypes,
SysColumns
LEFT JOIN SysProperties
ON (Syscolumns.Id = Sysproperties.Id AND Syscolumns.Colid = Sysproperties.Smallid)
WHERE (Sysobjects.Xtype =u OR Sysobjects.Xtype =v)
AND Sysobjects.Id = Syscolumns.Id
AND SysTypes.XType = Syscolumns.XType
AND SysTypes.Name sysname
AND SysObjects.name = jobs
如果需要查询整个数据库的所有表的话,就把最后哪个条件去掉即可。
以前写过类似的,参考一下:
declare @str nvarchar(20)
declare @tablename varchar(50)
declare @colname varchar(50)
declare @counts int
declare @sql nvarchar(2000)--以上定义变量
declare cur1 cursor for
select a.name tablename,B.name colname from sys.objects a,syscolumns b where a.object_id=b.id and a.type_desc='USER_TABLE'--定义游标
set @str='CT无袖开胸上衣' --设置要查找的字符
Open cur1 --打开游标
Fetch next From cur1 Into @tablename,@colname
While(@@Fetch_Status = 0) --循环
Begin
set @sql=N'select @counts=COUNT(*) from ' + @tablename + ' where charindex('''+@str+''','+@colname+')0'
exec sp_executesql @sql,N'@counts int output',@counts output --执行动态sql
if @counts0 --判断某个表某个字段是否存在特定字符
begin
print @tablename+','+@colname --打印表名及字段名
end
Fetch next From cur1 Into @tablename,@colname
End
Close cur1 --关闭游标
Deallocate cur1 --释放游标