SQL_查找用户的表属于哪个表空间,sql
***********************************************声明***********************************************************************
原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。
深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39756017
****************************************************************************************************************************
思路:根据区找到数据文件号,然后根据文件号在dba_data_files找到数据文件的路径,我们使用一条语句,通过表连接对数据进行关联。
样例:
SQL> select b.file_name,a.owner,a.segment_name from dba_extents a,dba_data_files b
where a.file_id=b.file_id and a.segment_name=$tablename and a.owner=&user;
演示:
根据dba_extents查找到文件号(FILE_ID),如下图:
再由FILE_ID在dba_data_files视图里查找到数据文件的路径,如下图:
SQL> select b.file_name,a.owner,a.segment_name from dba_extents a,dba_data_files b where a.file_id=b.file_id and a.segment_name='DEPT' and a.owner='SCOTT';
由以上语句可以查看到,dept表属于在users01.dbf这个表空间中,我们根据上面查询的路径,进入后可以查看到物理文件。
***********************************************声明***********************************************************************
原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。
深蓝的blog:http://blog.csdn.net/huangyanlong/article/details/39756017
****************************************************************************************************************************
需要有dba的权限1、查看用户使用的缺省表空间名称你一定知道你登陆的用户名是吧,以sysdba登陆。sqlplus / as sysdbaselect username,default_tablespace from dba_users;2、查看表空间总大小,及其已使用大小select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"from(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
需要有dba的权限
1、查看用户使用的缺省表空间名称
你一定知道你登陆的用户名是吧,
以sysdba登陆。
sqlplus / as sysdba
select username,default_tablespace from dba_users;
2、查看表空间总大小,及其已使用大小
select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",
round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"from(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b