/*
search a string in all databaes tables and all fields
*/if object_id(
'search_db')
isnot
null
drop
proc search_db
gocreate
proc search_db
@table nvarchar(
100),
@cond nvarchar(
512)
asdeclare hcforeach
cursor global
forselect
sqlstmt =
'if exists (' + stmt +
')print ''' + replace(stmt,
'''',
'''''') +
''''
from(
select
stmt=
'select * from [' + table_name +
'] where convert(nvarchar, [' + column_name +
']) like ''' + @cond +
''''
from information_schema.columns a
where (isnull(@
table,
'') =
''or
table_name
like
@table)
and data_type <>
'image'
and(
select
table_type
from information_schema.tables b
where a.table_name = b.table_name) =
'base table'
) texec sp_msforeach_worker @command1 = n
'?'go
exec search_db
'',
'%hkg%'
drop
proc search_db
查詢所有資料庫中的所有表的所有欄位的資訊
查詢所有資料庫中的所有表的所有欄位的資訊 declare s varchar 8000 set s select s s select select name as dbname,a.name as tablename,b.name as colname,c.name as coltype,c.le...
刪除當前資料庫所有表的方法
declare tables cursor cursor for select name from sysobjects where type u 選擇使用者表名 open tables cursor 開啟游標連線 declare tablename sysname 定義變數 fetch next ...
查詢資料庫所有表以及表的所有列
select from tab select a.b.comments from select t.table name,t.column name,t.data type from user tab cols t where table name entp show a left join sel...