1. 程式人生 > >在整個資料庫中查詢一個值

在整個資料庫中查詢一個值

v1=$1
sqlcmd -E -d trident1 -Q "SELECT 'SELECT '+''''+TABLE_NAME+'.'+COLUMN_NAME+''''+' AS NAME FROM dbo.'+TABLE_NAME+' WHERE CONVERT(varchar,['+COLUMN_NAME+'])='+''''+'$v1'+''''+' UNION ' FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE IN ('int','bigint','smallint','tinyint','char','nvarchar','varchar') UNION ALL SELECT TOP 1 'SELECT TOP 0 NAME FROM sys.objects' FROM sys.objects"|sed 's/([0-9]\{1,5\} rows affected)//' >temp.txt
attrib +H temp.txt
sqlcmd -E -d trident1 -i temp.txt
rm temp.txt