SQL取資料庫表名的方法

2021-05-25 02:08:11 字數 987 閱讀 7311

返回當前環境下可查詢的物件的列表(任何可出現在 from 子句中的物件)。

語法sp_tables

[   [@table_name      =]'name']        --物件

[,[@table_owner     =]'owner']       --表擁有者

[,[@table_qualifier =]'qualifier']  --資料庫名

[,[@table_type      =]"type"]       --物件型別

詳細情況請檢視sql幫助。

例項用法:

exec sp_tables @table_name='tb_stock_main', @table_owner='dbo', @table_qualifier='db_store', @table_type='''table'', ''system table'', ''view'' '

其中:   db_store為資料庫名,    tb_stock_main為資料庫db_store中的乙個表。

下面用法一樣的效果:

select * from sysobjects where xtype= 'u '   或

select * from sysobjects where objectproperty(id, 'isusertable ')=1

使用SQL查詢所有資料庫名和表名

show databases select table name from information schema.tables where table schema database name and table type base table select column name from inf...

使用SQL查詢所有資料庫名和表名

show databases select table name from information schema.tables where table schema database name andtable type base table select column name from info...

sql查詢資料庫中所有表名 續

讀取庫中的所有表名 select name from sysobjects where xtype u 讀取指定表的所有列名 select name from syscolumns where id select max id from sysobjects where xtype u and na...