導航:首頁 > 數據分析 > 如何查詢資料庫關鍵欄位

如何查詢資料庫關鍵欄位

發布時間:2023-06-08 15:24:17

㈠ 如何查找資料庫中某一欄位值

1.查詢資料庫中的所有資料庫名:
SELECT Name FROM Master..SysDatabases ORDER BY Name

2.查詢某個資料庫中所有的表名:
SELECT Name FROM SysObjects Where XType='U' ORDER BY Name

3.查詢表結構信息:

1 SELECT (case when a.colorder=1 then d.name else null end) 表名,
2 a.colorder 欄位序號,a.name 欄位名,
3 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 標識,
4 (case when (SELECT count(*) FROM sysobjects
5 WHERE (name in (SELECT name FROM sysindexes
6 WHERE (id = a.id) AND (indid in
7 (SELECT indid FROM sysindexkeys
8 WHERE (id = a.id) AND (colid in
9 (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))
10 AND (xtype = 'PK'))>0 then '√' else '' end) 主鍵,b.name 類型,a.length 佔用位元組數,
11 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 長度,
12 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小數位數,(case when a.isnullable=1 then '√'else '' end) 允許空,
13 isnull(e.text,'') 默認值,isnull(g.[value], ' ') AS [說明]
14 FROM syscolumns a
15 left join systypes b on a.xtype=b.xusertype
16 inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
17 left join syscomments e on a.cdefault=e.id
18 left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
19 left join sys.extended_properties f on d.id=f.class and f.minor_id=0
20 where b.name is not null
21 --WHERE d.name='要查詢的表' --如果只查詢指定表,加上此條件
22 order by a.id,a.colorder

㈡ 如何使用sql server查詢整個資料庫某一個關鍵字

感覺你最好先搞個查詢,別直接替換,風險太大。

代碼如下(這個是查找庫里所有記錄中含「張三」的數據,替換里邊的張三那個字元串就行):

declare@cloumnsvarchar(40)
declare@tablenamevarchar(40)
declare@strvarchar(40)
declare@countsint
declare@sqlnvarchar(2000)
declareMyCursorCursorFor
Selecta.nameasColumns,b.,sysobjectsb,systypesc
wherea.id=b.id
andb.type='U'
anda.xtype=c.xtype
andc.namelike'%char%'
set@str='張三'
OpenMyCursor
FetchnextFromMyCursorInto@cloumns,@tablename
While(@@Fetch_Status=0)
Begin
set@sql='select@tmp_counts=count(*)from'+@tablename+'where'+@cloumns+'='''+@str+''''
executesp_executesql@sql,N'@tmp_countsintout',@countsout
if@counts>0
begin
print'表名為:'+@tablename+',欄位名為'+@cloumns
end
FetchnextFromMyCursorInto@cloumns,@tablename
End
CloseMyCursor
DeallocateMyCursor

㈢ mysql資料庫如何搜索關鍵詞

辦法如下:

select * from table1 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union
select * from table2 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union
select * from table3 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union
select * from table4 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%' union
select * from table5 where concat(`欄位`,`欄位`,`欄位` ) like '%關鍵字%'
前提是查詢出來的欄位個數要一樣,類型要對應好,至於如何得到正確且符合你需要的sql就要在程序類中處理了。

㈣ sql 資料庫中所有表中查詢關鍵字

用游標循環以下,可能效率有點低,以下是我寫的一個存儲過程語句供參考
--exec searchkeyword '物理'
Create proc searchkeyword(@keyword varchar(100))
as
begin
declare @tablename varchar(100),@colname varchar(100),@sql nvarchar(2000),@cou int
create table #t
(
tablename varchar(100),
colname varchar(100)
)
declare c1 cursor for
select a.name as TableName,b.name as ColName From sysobjects a
inner join syscolumns b on (a.id=b.id)
where a.xtype='U'
open c1
fetch next from c1 into @tablename,@colname
WHILE @@_STATUS = 0
begin
set @sql='select @count=count(*) from '+@tablename+' where '+@colname+'=@keyword'
begin try
exec sp_executesql @sql, N'@count int out,@keyword varchar(20)', @cou out ,@keyword
end try
begin catch
set @cou=0
end catch
if @cou>0
begin
insert into #t values(@tablename,@colname)
end
fetch next from c1 into @tablename,@colname
end
CLOSE c1
DEALLOCATE c1
select * from #t
end

㈤ 如何查詢輸出資料庫中包含某欄位關鍵詞的全部條目

1.查詢資料庫中的所有資料庫名:
SELECT Name FROM Master..SysDatabases ORDER BY Name

2.查詢某個資料庫中所有的表名:
SELECT Name FROM SysObjects Where XType='U' ORDER BY Name

3.查詢表結構信息:

1 SELECT (case when a.colorder=1 then d.name else null end) 表名,
2 a.colorder 欄位序號,a.name 欄位名,
3 (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 標識,
4 (case when (SELECT count(*) FROM sysobjects
5 WHERE (name in (SELECT name FROM sysindexes
6 WHERE (id = a.id) AND (indid in
7 (SELECT indid FROM sysindexkeys
8 WHERE (id = a.id) AND (colid in
9 (SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))
10 AND (xtype = 'PK'))>0 then '√' else '' end) 主鍵,b.name 類型,a.length 佔用位元組數,
11 COLUMNPROPERTY(a.id,a.name,'PRECISION') as 長度,
12 isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小數位數,(case when a.isnullable=1 then '√'else '' end) 允許空,
13 isnull(e.text,'') 默認值,isnull(g.[value], ' ') AS [說明]
14 FROM syscolumns a
15 left join systypes b on a.xtype=b.xusertype
16 inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
17 left join syscomments e on a.cdefault=e.id
18 left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
19 left join sys.extended_properties f on d.id=f.class and f.minor_id=0
20 where b.name is not null
21 --WHERE d.name='要查詢的表' --如果只查詢指定表,加上此條件
22 order by a.id,a.colorder

閱讀全文

與如何查詢資料庫關鍵欄位相關的資料

熱點內容
列表文件存儲路徑 瀏覽:540
qq游戲大廳自動出語音 瀏覽:598
編程只是興趣怎麼辦 瀏覽:223
榮耀6plus電信版本 瀏覽:584
能打開word文件但桌面上找不到 瀏覽:366
2020十大網路紅歌有哪些 瀏覽:843
手機系統空間文件夾在哪裡設置快捷鍵 瀏覽:309
通信網路中的b8什麼意思 瀏覽:715
桌面文件標題 瀏覽:228
優淘集市有什麼app 瀏覽:747
找不到收藏文件 瀏覽:711
戰狼2在什麼網站 瀏覽:785
vb修改word 瀏覽:650
c盤分頁文件 瀏覽:277
ipad如何互相傳輸數據 瀏覽:567
我的世界如何用積木編程大師復制方塊 瀏覽:638
進網站請求路徑未找到是怎麼回事 瀏覽:807
spss21教程 瀏覽:655
css商業網站布局之道pdf 瀏覽:892
c盤不能新建文件夾win10 瀏覽:384

友情鏈接