oracle表空间

 1 --查询所有的表空间及空间大小
 2 select a.tablespace_name, total, free, total - free used
 3   from (select tablespace_name, sum(bytes) / 1024 / 1024 total
 4           from dba_data_files
 5          group by tablespace_name) a,
 6        (select tablespace_name, sum(bytes) / 1024 / 1024 free
 7           from dba_free_space
 8          group by tablespace_name) b
 9  where a.tablespace_name = b.tablespace_name;
10 
11 --查询用户的表空间
12 select username,default_tablespace from user_users;
13 
14 select username,default_tablespace from dba_users order by username;
15 --创建表空间
16 create tablespace xm datafile'c:/xmm.mdf' size 50m
17 --创建用户
18 create user zs identified by zs default tablespace xm;
19 --给用户授权
20 GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW , DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE, DBA,CONNECT,RESOURCE,CREATE SESSION  TO his_nh
30 --新增数据文件,并且允许数据文件自动增长
31 ALTER TABLESPACE users ADD DATAFILE
32 'D:\USERS_LSP_3.DBF' SIZE 1g
33 AUTOEXTEND ON NEXT 50M MAXSIZE 10g;
34 
35 --删除表空间,同时删除数据文件:
36 drop tablespace test_data including contents and datafiles;
37 
38 --查询所有的表空间及空间大小
39 SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
40          D.TOT_GROOTTE_MB "表空间大小(M)",
41          D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
42          TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) /
43                        D.TOT_GROOTTE_MB * 100,
44                        2),
45                  '990.99') || '%' "使用比",
46          F.TOTAL_BYTES "空闲空间(M)",
47          F.MAX_BYTES "最大块(M)"   FROM (SELECT TABLESPACE_NAME,
48                                                ROUND(SUM(BYTES) /
49                                                      (1024 * 1024),
50                                                      2) TOTAL_BYTES,
51                                                ROUND(MAX(BYTES) /
52                                                      (1024 * 1024),
53                                                      2) MAX_BYTES   FROM SYS.DBA_FREE_SPACE   GROUP BY TABLESPACE_NAME) F,
54           (SELECT DD.TABLESPACE_NAME,
55                      ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB   FROM SYS.DBA_DATA_FILES DD   GROUP BY DD.TABLESPACE_NAME) D   WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME   ORDER BY 1;
56 --如果dmp文件很小,但是导入之后非常大,有可能是由于导入的时候默认使用了原来的Intial extent
57 
58 --查看清华图书视图的定义: 
59 SELECT TEXT FROM USER_VIEWS WHERE VIEW_NAME='清华图书';
60 --查看用户拥有的视图: 
61 SELECT object_name FROM user_objects WHERE object_type='VIEW';  
62 
63 --指定SQL 使用索引
64 select /*+book myindex*/ *  from book where bid like '2%';
65 --增大表空间(添加新的数据块)
66 
67 ALTER TABLESPACE "USERS" ADD DATAFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF' SIZE 1024M AUTOEXTEND ON NEXT 50M MAXSIZE UNLIMITED;
68 select * from v$datafile
69 
70 //删除表数据
71 SELECT 'TRUNCATE TABLE '|| table_name || ';' FROM USER_TABLES
72 ORDER BY TABLE_NAME;

 

posted on 2016-06-03 14:48  ..小树苗  阅读(768)  评论(0编辑  收藏  举报

导航