C 獲取資料庫中所有的表名

2021-06-01 03:23:41 字數 685 閱讀 9555

select name

from sysobjects

where xtype = 'u' --使用者表,系統表是's'

近日使用oledb來操作excel檔案,xls檔案裡面當然不可能會存在sysobjects這個系統表,這時候我們需要用oledbconnection裡面的乙個函式來返回資料庫的結構表,從而獲得所有表的名稱:

const string szconnectstring = "provider=microsoft.ace.oledb.12.0; data source=c:\\1.xlsx; extended properties=\"excel 12.0;hdr=yes;\"";

oledbconnection connobj = new oledbconnection(szconnectstring);

datatable schematable = connobj.getoledbschematable(system.data.oledb.oledbschemaguid.tables_info, null);

查閱msdn可以知道,getoledbschematable函式中第乙個引數的意義是「返回給定使用者可訪問的表(包括檢視)」,schematable的列是按固定的順序輸出的,其中第三列即為table_name

參考了這裡,感謝wuyq11:

查詢資料庫中所有的表

select from sysobjects where xtype u 查詢當前資料庫下所有使用者建立的表 xtype char 2 物件型別。可以是下列物件型別中的一種 c check 約束 d 預設值或 default 約束 f foreign key 約束 l 日誌 fn 標量函式 if 內...

如何獲取Mysql資料庫中所有表名

歡迎加入bim行業開發交流1群 群號 711844216 小夥伴們在使用資料庫時,有時候不止需要訪問其中的乙個表,而是多個表,這個時候就需要首先獲取資料庫中的表名,然後迴圈讀取表了。sql語句 show tables from 資料庫名 using system using system.colle...

獲得資料庫中所有的表

在資料庫中一般都會有乙個系統表來記錄下所有的使用者表或檢視,儲存過程等等的.名字就叫sysobjects.所有要查詢出所有的表可以用以下語句 sql2000 select from sysobjects where xtype u或 v 或 p access select from msysobje...