//导出数据
$ exp cicro/cicro@127.0.0.1:1521/orcl buffer=64000 file=CsInfo_jsw.dmp tables=cs_info query=\"WHERE site_id\=\'rkjs\'\"
$ exp cicro/cicro@127.0.0.1:1521/orcl buffer=64000 file=CsInfoArticle_jsw.dmp tables=cs_info_article query=\"WHERE site_id\=\'rkjs\'\"
$ imp cicro/cicro@127.0.0.1:1521/orcl file=CsInfo_jsw.dmp full=y ignore=y
$ imp cicro/cicro@127.0.0.1:1521/orcl file=CsInfoArticle_jsw.dmp full=y ignore=y
//只导出数据库结构
$ exp cicro/cicro@127.0.0.1:1521/db1 buffer=64000 file=CsInfo_jsw.dmp rows=n"
//查看当前表空间
select default_tablespaces from user_users;
//一下部分来自网络
ORACLE数据库会对产生改变的操作记录REDO,比如DDL语句、DML语句,这些操作首先会放在redo buffer中,然后由LGER进程根据触发条件写到联机日志文件,如果数据库开启归档的话,还要在日志切换的时候归档。在这样一个完整的链条上的每一个环节,都可能会成为性能的瓶颈,所以需要引起DBA和数据库应用人员的注意。
下面案例中,当把一个表设置成NOLOGGING模式的时候,通过一定的插入操作,可以让oracle产生较少的REDO。
SQL> conn / as sysdba
SQL> archive log list --此时为归档模式
SQL> create table tj as select * from dba_objects where 1=2;
SQL> select count(*) from tj;
SQL> select table_name,logging from user_tables where table_name='TJ';
--观察logging属性值
SQL> set autotrace on stat
SQL> insert into tj select * from dba_objects; --观察redo size的统计值
SQL> rollback;
SQL> insert /*+append*/ into tj select * from dba_objects; --观察redo size的统计值
SQL> rollback;
SQL> alter table tj nologging;
SQL> select table_name,logging from user_tables where table_name='TJ';
--观察logging属性值
SQL> insert into tj select * from dba_objects; --观察redo size的统计值
SQL> rollback;
SQL> insert /*+append*/ into tj select * from dba_objects; --观察redo size的统计值
补充说明:设置Autotrace的命令
用法: SET AUTOT[RACE] {OFF | ON | TRACE[ONLY]} [EXP[LAIN]] [STAT[ISTICS]]
--关闭跟踪执行计划和统计信息功能(默认关闭)。
SQL> set autotrace off;
--执行计划和统计信息都显示
SQL> set autotrace on ;
--只显示执行计划和统计信息,不显示sql执行结果。
SQL> set autotrace traceonly;
--只显示执行计划
SQL> set autotrace on explain;
--只显示统计信息
SQL> set autotrace on statistics;
补充说明:归档模式与非归档模式间的转换命令
--1)关闭数据库
SQL>shutdown immediate
--2)把数据库启动到mount的模式
SQL>startup mount
--3)把数据库改为非归档模式 /归档模式
SQL>alter database noarchivelog;
或者
SQL>alter database archivelog;
--4)打开数据库
SQL>Alter database open;
--5)查看数据库归档模式的状态
SQL> archive log list
备注:如果在关闭归档日志时出现ORA-38774错误,请关闭flash闪回数据库模式。
SQL> alter database flashback off
案例2
创建一张基本表
Create tablespace exampletb
Datafile 'E:\ examp01.dbf' reuse;
CREATE TABLE scott.student
(id NUMBER(5) CONSTRAINT st_id_pk PRIMARY KEY,
name VARCHAR2(10) CONSTRAINT st_name NOT NULL,
phone VARCHAR2(11),
school_time DATE DEFAULT SYSDATE,
sex CHAR(1),
CONSTRAINT st_sex_ck CHECK (sex IN('F','M')),
CONSTRAINT st_ph_uk UNIQUE (name))
INITRANS 1 MAXTRANS 255
PCTFREE 20 PCTUSED 50
STORAGE( INITIAL 1024K NEXT 1024K PCTINCREASE 0 MINEXTENTS 1 MAXEXTENTS 5)
TABLESPACE exampletb
2、 修改表结构
Alter table 表名 add (列名 类型); --添加新列
Alter table 表名 modify (列名 类型); --修改列定义
Alter table 表名 drop column 列名; --删除列
Rename 表名 to 新表名 --改表名(表名前不能加方案名)
ALTER TABLE 表名 RENAME COLUMN 当前列名 TO 新列名; --修改列名
修改表结构案例
SQL> Alter table scott.student add (QQ number(10));
--为student表增加列存放QQ号
SQL> Alter table scott.student modify (QQ number(12));
--修改student表中名为QQ的列
SQL> Alter table scott.student rename COLUMN QQ to QQ_num;
--将student表中名为QQ的列改名QQ_num
SQL> Alter table scott.student drop column QQ_num;
--删除student表中名为QQ_num的列
SQL> insert into scott.student(id,name) values(1, 'lucy');
--向student表中插入一条记录
SQL> Alter table scott.student modify (sex char(1) default 'M');
--修改sex列的定义
SQL> insert into scott.student(id,name) values(2, 'Dell');
--向student表中插入一条记录
SQL> Alter table scott.student modify (sex char(1) default null);
--修改sex列的定义
SQL> insert into scott.student(id,name) values(3, 'Mary');
--向student表中插入一条记录
思考:oracle中列的默认值设置与修改。
3、 表的约束
Alter table 表名 add constraint 约束 ; --增加一个约束
Alter table 表名 drop constraint 约束名; --删除一个约束
alter table表名enable [validate/novalidate] constraint约束名;
--启用一个约束,validate/novalidate代表启用约束时是否对表中原有数据作检查。
alter table表名disable constraint约束名; --禁用一个约束
修改表约束案例
SQL> Alter table scott.student disable constraint st_sex_ck;
--禁用st_sex_ck约束
SQL> insert into scott.student(id,name,sex) values(4, 'Lily', 'N');
SQL> Alter table scott.student enable novalidate constraint st_sex_ck;
--启用st_sex_ck约束,但不检查已有数据。
SQL> select * from scott.student;
SQL> insert into scott.student(id,name,sex) values(5, 'Mark', 'N');
SQL>@$ORACLE_HOME/rdbms/admin/utlexpt1.sql --建立异常数据保存表
或者
@ G:\app\Administrator\product\11.2.0\dbhome_1\RDBMS\ADMIN\utlexpt1.sql
--具体路径可以通过搜索utlexpt1.sql获取
SQL>alter table scott.student enable validate constraint st_sex_ck exceptions into exceptions; -- 将异常数据装入异常表
SQL> select * from scott.student where rowid in(select row_id from exceptions);
--查看对应的原表中的异常数据
SQL>Alter table scott.student drop constraint st_sex_ck; --删除约束st_sex_ck
本文介绍了Oracle数据库的导出导入操作、表空间查询、表结构管理等实用技巧,并通过案例展示了如何通过调整表的LOGGING属性来减少REDO日志生成,从而达到性能优化的目的。
1万+

被折叠的 条评论
为什么被折叠?



