怎么知道DB里面有多少table

Jerrylew 2005-12-26 03:12:00
当连到一个DB的时候,怎么知道这个DB里面有多少table,并得到每张table的名称

--
多谢
...全文
384 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jerrylew 2005-12-27
  • 打赏
  • 举报
回复
感 谢 大 家
kingofhawks 2005-12-27
  • 打赏
  • 举报
回复
学海无涯~~
Mark_Chen 2005-12-27
  • 打赏
  • 举报
回复
顶!!
pb_java 2005-12-27
  • 打赏
  • 举报
回复
楼上的正解.
chenshengli 2005-12-26
  • 打赏
  • 举报
回复
select * from tab
humanity 2005-12-26
  • 打赏
  • 举报
回复
Connection conn = null;
DatabaseMetaData dbMeta = conn.getMetaData();

ResultSet rs = dbMeta.getTables("%","MySchemaAsUsername","%",new String[]{"TABLE","VIEW"});

ResultSetMetaData rsMeta = rs.getMetaData();
while(rs.next()){
StringBuffer b = new StringBuffer();
for (int i = 0; i < rsMeta.getColumnCount(); i++) {
b.append(rsMeta.getColumnLabel(i+1)).append('=').append(rs.getString(i+1));
}
System.out.println(b);
}
fairy392 2005-12-26
  • 打赏
  • 举报
回复
学习ing…… 哈哈又学到东西啦:)
leekooqi 2005-12-26
  • 打赏
  • 举报
回复
楼上正解
cenlmmx 2005-12-26
  • 打赏
  • 举报
回复
oracle: select count(*) from V$user_tables
sqlserver: select count(*) from sysobjects where type='U'
MYLiao 2005-12-26
  • 打赏
  • 举报
回复
以上是SQL Server的所有用户表
MYLiao 2005-12-26
  • 打赏
  • 举报
回复
或者:

select * from sysobjects where type='U'

MYLiao 2005-12-26
  • 打赏
  • 举报
回复
select * from sysobjects where xtype='U'
Jerrylew 2005-12-26
  • 打赏
  • 举报
回复
感谢楼上,
也许我没有把问题说得清楚,当我用java的Connection连好数据库,这时我想知道这个数据库里可以给这个user所能查看的table(不是view)有多少,都叫什么名字
稽姬 2005-12-26
  • 打赏
  • 举报
回复
oracle里你可以知道哪个用户有多少个表,用system用户登录,有一个叫dba_tables的视图那里有用户表的信息

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧