标签:
今天有时间将oracle数据库的笔记整理一下。在开发过程中,多多少少会涉及一些数据库方面的东西,将这些东西整理下来还是有必要滴。
/*第一步:创建数据库实例*/
可根据oracle自带的配置实例的步骤一步一步建好。
/*第二步:创建表空间*/
用管理员身份登录后,
CREATE TABLESPACE TSP_TEST_PROVINCE DATAFILE ‘C:/app/Administrator/oradata/test/TSP_TEST_PROVINCE.dbf‘ SIZE 5024M AUTOEXTEND ON NEXT 1024M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL; CREATE SMALLFILE TEMPORARY TABLESPACE TSP_TEST_TEMP TEMPFILE ‘C:/app/Administrator/oradata/test/TSP_TEST_TEMP.dbf‘ SIZE 1024M AUTOEXTEND ON NEXT 1024M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL;
/*第三步:创建用户*/
CREATE USER TESTDB IDENTIFIED BY TESTDB DEFAULT TABLESPACE TSP_TEST_PROVINCE TEMPORARY TABLESPACE TSP_TEST_TEMP ACCOUNT UNLOCK; GRANT CONNECT,DBA,RESOURCE,UNLIMITED TABLESPACE TO TESTDB ;
/*导入数据库*/
connect sys/password as sysdba
(1)connect sys/password as sysdba
(2)create directory dmp_dir as ‘e:\dmp’;
grant read,write on directory dmp_dir to TEXTDB;
(3)impdp TEXTDB/TEXTDB@TEXT directory=dmp_dir dumpfile=TEXTDB.dmp logfile=TEXTDB.log
/**扩展表空间*/
ALTER TABLESPACE TSP_TEST_TEMP1 ADD DATAFILE ‘C:/app/Administrator/oradata/test/TSP_TEST_TEMP1.dbf‘
SIZE 100M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED;
/**删除表空间及其文件*/
DROP TABLESPACE TSP_TEST_TEMP1 INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
/**添加表空间文件*/
ALTER TABLESPACE TSP_TEST_TEMP1 ADD DATAFILE ‘C:/app/Administrator/oradata/test/TSP_TEST_TEMP2.dbf‘ SIZE 32767M;
/**查看表空间使用*/
SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)", TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),‘990.99‘) || ‘%‘ "使用比", F.TOTAL_BYTES "空闲空间(M)", F.MAX_BYTES "最大块(M)" FROM (SELECT TABLESPACE_NAME, ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES, ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES FROM SYS.DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F, (SELECT DD.TABLESPACE_NAME, 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;
/**查询表空间下所有的表*/
select * from all_tables where tablespace_name=‘TSP_TEST_TEMP1 ‘
/**查询表空间被使用*/
select segment_name,partition_name,tablespace_name from
dba_extents where tablespace_name=upper(‘TSP_TEST_TEMP1 ‘)
标签:
原文地址:http://www.cnblogs.com/sierrajuan2015/p/4832068.html