查詢指定的表在那些資料庫中存在

2021-03-31 19:18:26 字數 768 閱讀 6323

--查詢指定的表在那些資料庫中存在

declare @tbname sysname

set @tbname='客戶資料'

declare @dbname sysname,@sql nvarchar(4000),@re bit,@sql1 varchar(8000)

set @sql1=''

declare tb cursor for select name from master..sysdatabases

open tb

fetch next from tb into @dbname

while @@fetch_status=0

begin

set @sql='set @re=case when exists(select 1 from ['

+@dbname+']..sysobjects where xtype=''u'' and name='''

+@tbname+''') then 1 else 0 end'

exec sp_executesql @sql,n'@re bit out',@re out

if @re=1 set @sql1=@sql1+' union all select '''+@dbname+''''

fetch next from tb into @dbname

endclose tb

deallocate tb

set @sql1=substring(@sql1,12,8000)

exec(@sql1)

查詢指定的表在那些資料庫中存在

查詢指定的表在那些資料庫中存在 declare tbname sysname set tbname 客戶資料 declare dbname sysname,sql nvarchar 4000 re bit,sql1 varchar 8000 set sql1 declare tb cursor fo...

查詢指定的物件在那些資料庫中存在

create proc find object object name varchar 100 xtype varchar 2 as object name 物件名 xtype 物件的型別 物件型別。可以是下列物件型別中的一種 c check 約束 d 預設值或 default 約束 f forei...

順序表查詢指定元素

問題描述 本題要求實現一個函式,要求從順序表中查詢指定元素,並返回第一個查詢成功的元素在表中的位置序號,若查詢失敗,則返回0 函式介面定義 int locateelem sqlist l,elemtype e 其中sqlist結構定義如下 typedef structsqlist 裁判測試程式樣例 ...

指定的表的列名無效 聯表查詢 列名無效

用到聯表查詢sql語句時 最後執行輸出總是報錯 說s.jprice列名無效 但這條語句在sqlserver中是可以執行的 到底是怎麼回事呀 求解 謝謝各位大神 jprice,mprice是spinfo表中的進價和賣價 xscout是xsjilu表中的銷售數量 iid是兩個表中的主外來鍵關聯 publ...

獲取指定表的表結構

最近公司專案中需要做一個使用excel員工匯入的需求,在匯入過程中,需要對資料核驗,就需要獲取相應的表結構的欄位型別,及其型別精度。以下為 private mapgetcolumninfo else if map.get numeric precision null else if map.get ...