oracle常用命令
[ 2004-09-09 01:19:25 | Author: 振华 ]
1、如何单独备份一个或多个用户:
D:\>exp scott/tiger file=导出文件
D:\>exp system/manager owner=(用户1,用户2,…,用户n) file=导出文件
2、如何单独备份一个或多个表:
D:\>exp 用户/密码 tables=表
D:\>exp 用户/密码 tables=(表1,…,表2)
D:\>exp system/manager tables=(用户.表)
D:\>exp system/manager tables=(用户1.表1,用户2.表2)
3、如何导入指定表
D:\>exp scott/tiger file=a.dmp
D:\>imp test/test fromuser=scott tables=emp file=a.dmp
D:\>imp test/test tables=dept file=a.dmp
(说明:如果导出用户没有DBA权限,则导入用户可以不用指定fromuser、touser参数
如果导出用户拥有DBA权限,则导入用户也必须拥有DBA权限)
4、如何给表、列加注释
SQL>comment on table 表 is '表注释';
注释已创建。
SQL>comment on column 表.列 is '列注释';
注释已创建。
SQL> select * from user_tab_comments where comments is not null;
SQL> select * from user_col_comments where comments is not null;
5、
查看当前用户下有什么对象(表、视图、同义词、快照)
SQL> select * from tab;
查看表结构
SQL> describe 表名
简写以上命令
SQL> desc 表名
6、
DDL、数据定义语言:create、alter、drop、truncate(创建、修改结构、删除、截断)(其他:rename)
DML、数据操纵语言:insert、delete、select、update(增、删、查、改)
DCL、数据控制语言:grant、revoke(授权、回收)、set role
事务控制:commit、rollback、savepoint(其他:lock table、set constraint(s)、set transaction)
审计控制:audit、noaudit
系统控制:alter system
会话控制:alter session
其他语句:comment(添加注释)、explain plan、analyze(收集统计)、validate、call
7、
1)、查看当前所有对象
SQL> select * from tab;
2)、建一个和a表结构一样的空表
SQL> create table b as select * from a where 1=2;
SQL> create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;
3)、察看数据库的大小,和空间使用情况
SQL> col tablespace format a20
SQL> select b.file_id 文件ID,
b.tablespace_name 表空间,
b.file_name 物理文件名,
b.bytes 总字节数,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space --表空间剩余空%
Comments Feed: http://www.zhenhua.org/feed.asp?q=comment&id=185
D:\>exp scott/tiger file=导出文件
D:\>exp system/manager owner=(用户1,用户2,…,用户n) file=导出文件
2、如何单独备份一个或多个表:
D:\>exp 用户/密码 tables=表
D:\>exp 用户/密码 tables=(表1,…,表2)
D:\>exp system/manager tables=(用户.表)
D:\>exp system/manager tables=(用户1.表1,用户2.表2)
3、如何导入指定表
D:\>exp scott/tiger file=a.dmp
D:\>imp test/test fromuser=scott tables=emp file=a.dmp
D:\>imp test/test tables=dept file=a.dmp
(说明:如果导出用户没有DBA权限,则导入用户可以不用指定fromuser、touser参数
如果导出用户拥有DBA权限,则导入用户也必须拥有DBA权限)
4、如何给表、列加注释
SQL>comment on table 表 is '表注释';
注释已创建。
SQL>comment on column 表.列 is '列注释';
注释已创建。
SQL> select * from user_tab_comments where comments is not null;
SQL> select * from user_col_comments where comments is not null;
5、
查看当前用户下有什么对象(表、视图、同义词、快照)
SQL> select * from tab;
查看表结构
SQL> describe 表名
简写以上命令
SQL> desc 表名
6、
DDL、数据定义语言:create、alter、drop、truncate(创建、修改结构、删除、截断)(其他:rename)
DML、数据操纵语言:insert、delete、select、update(增、删、查、改)
DCL、数据控制语言:grant、revoke(授权、回收)、set role
事务控制:commit、rollback、savepoint(其他:lock table、set constraint(s)、set transaction)
审计控制:audit、noaudit
系统控制:alter system
会话控制:alter session
其他语句:comment(添加注释)、explain plan、analyze(收集统计)、validate、call
7、
1)、查看当前所有对象
SQL> select * from tab;
2)、建一个和a表结构一样的空表
SQL> create table b as select * from a where 1=2;
SQL> create table b(b1,b2,b3) as select a1,a2,a3 from a where 1=2;
3)、察看数据库的大小,和空间使用情况
SQL> col tablespace format a20
SQL> select b.file_id 文件ID,
b.tablespace_name 表空间,
b.file_name 物理文件名,
b.bytes 总字节数,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
/
dba_free_space --表空间剩余空%
删除表:
drop table 表名
导入:
drop
imp username/password@表名 orcl
导出:
exp user/pass@服务名l
插入字段:
alter table *** add ZD varchar2(20) default 0 not null;
comment on colum **.ZD is '说明';
drop table 表名
导入:
drop
imp username/password@表名 orcl
导出:
exp user/pass@服务名l
插入字段:
alter table *** add ZD varchar2(20) default 0 not null;
comment on colum **.ZD is '说明';
Comments Feed: http://www.zhenhua.org/feed.asp?q=comment&id=185
There is no comment on this article.










