根據字段值 查詢 欄位名,表名

2021-06-03 05:44:16 字數 783 閱讀 7579

declare @what varchar(800)

set @what='bffc43e1-6646-434e-b47d-0a32ac793b1c' --要搜尋的字串 

declare @sql varchar(8000) 

declare tablecursor cursor local for

select sql='if exists ( select 1 from ['+o.name+'] where ['+c.name+'] like ''%'+@what+'%'' ) print ''所在的表及字段:['+o.name+'].['+c.name+']'''

from syscolumns c join sysobjects o on c.id=o.id 

-- 175=char 56=int 可以查 select * from sys.types 

where o.xtype='u' and c.status>=0 and c.xusertype in (175, 239, 231, 167 ) 

open tablecursor 

fetch next from tablecursor into @sql

while @@fetch_status=0

begin

exec( @sql )

fetch next from tablecursor into @sql

end 

close tablecursor 

-- 刪除游標引用

deallocate tablecursor 

mysql通過字段注釋查詢欄位名稱

原文 mysql通過字段注釋查詢欄位名稱 有時候表的字段太多,只是大致記得表的注釋,想通過字段注釋查詢欄位名稱,可以用如下語句 select column name,column comment from information schema.columns where table name tj ...

SQL查表名 欄位名 表說明 字段說明

sql 檢視所有表名 select name from sysobjects where type u 查詢表的所有欄位名 select name from syscolumns where id object id 表名 select from information schema.tables ...

查詢表的欄位名

select name from syscolumns where id in select id from sysobjects where type u and name 相應表名 用以上sql語句輸入相應表名就可以查到表的欄位名,對應好資料庫 查詢是否存在該錶語句 if exists sele...