create user test> drop user test cascade; 用户下有数据也可以删除。不加cascade的话,用户下有数据则无法删除。
分配权限
grant connect,resource,unlimited tablespace to test;将连接(登录)权限分配给test用户,自己资源使用权限,对表空间大小限制权限;
sql>conn test/test 连接到test用户
desc user_tables;描述表结构
select 列名 from user_tables;
show users;查看当前用户
对列起别名
select sysdata-7 "ADD" from dual;对sysdata-7的结果起一个别名“ADD”
truncata 和delete的区别
truncate是在数据库底层将数据存放的空间都删除了
delete是将数据删除了,但是数据存放的空间还在,可以通过技术手段恢复
delete数据库后如何恢复
select * from table as of timestamp to_timestamp('2014-2-19 10:44:00','yyyy=mm-ddd hh24:mi:ss');
以上条件还能查询到数据
select * from table as of timestamp to_timestamp('2014-2-19 10:57:00','yyyy=mm-ddd hh24:mi:ss');
以上条件无法查询到数据
说明数据删除时间是在以上两个时间范围内
insert into table select * from table as of timestamp to_timestamp('2014-2-19 10:44:00','yyyy=mm-ddd hh24:mi:ss');
即可将数据恢复。
函数minus ---减的意思
insert into table
(select * from table as of timestamp to_timestamp('2014-2-19 10:44:00','yyyy=mm-ddd hh24:mi:ss'))
minus
(select * from table as of timestamp to_timestamp('2014-2-19 10:57:00','yyyy=mm-ddd hh24:mi:ss'));
用前一个时间减去后一个时间,得到差异的数据,插入到原表中
备份
1、创建一个备份表
2、通过exp导出的方式备份(可以在服务器端,也可以在客户端导,速度慢)
3、通过expdp导出的方式备份(只能在服务器端导,速度快)
4、通过rman备份(可基于时间节点进行恢复)truncate后也可以恢复
backup database
backup tablespace
restore恢复
recover恢复
创建索引
create index index_test on table(a);对table表的a列建索引
数据库性能监控