oracle数据库的基本操作语句
1、创建表空间
// 创建表空间 大小为1024MB 自动增长 1024MB
create tablespace user1_space logging datafile 'C:/app/lenovo/admin/orcl/adump/user1_space.dbf' size 1024M autoextend on next 1024M maxsize unlimited extent management local;
// 创建临时表空间
create temporary tablespace user1_temp tempfile 'C:/app/lenovo/admin/orcl/adump/user1_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
// 修改表空间名称 将表空间user1_space 改为user2_space
alter tablespace user1_space rename to user2_space ;
// 查询表空间信息
select tablespace_name from dba_tablespaces;
// 修改表空间大小
Alter database datafile ‘表空间路径’ resize 2000m;
// 删除表空间及文件
drop tablespace user1_space including contents and datafiles cascade constraint;
2、创建用户
// 创建用户
CREATE USER USERNAME PROFILE DEFAULT IDENTIFIED BY PASSWORD
// 创建用户username 并指定表空间
create user username identified by PASSWORD default tablespace user1_space Temporary TABLESPACE user1_temp;
// 给已存在的用户指定表空间
alter user username default tablespace user1_space ;
// 删除用户 指定 cascade 会删除用户下的所有对象(包括表、视图、主键、外键、索引等;但不会删除存储过程、函数、包)。如果不指定则仅仅只删除用户,一般建议指定
drop user username cascade;
3、管理员给用户授权
// 授予用户username管理员权限
grant dba to username;
// 授予username用户创建session的权限,即登陆权限,允许用户登录数据库
grant create session to username;
// 授予username用户使用表空间的权限
grant unlimited tablespace to username;
// 授予创建表的权限
grant create table to username;
// 授予删除表的权限
grante drop table to username;
// 插入表的权限
grant insert table to username;
// 修改表的权限
grant update table to username;
// 这条比较重要,授予所有权限(all)给所有用户(public)
grant all to public;
4、撤销权限
基本语法同grant,关键字为revoke
5、查看权限
// 查看当前用户所有权限
select * from user_sys_privs;
//查看所用用户对表的权限
select * from user_tab_privs;
6、oralce 中一些常用的操作
// 查询所有的用户
select * from all_users ; select * from dba_users;
// 查询当前用户信息
select * from dba_ustats;
// 查询表空间路径信息
select * from dba_data_files
// 查询表空间名称
select tablespace_name from user_tablespaces;
// 查询系统路径信息
select * from Dba_Directories
7、数据回滚
1、 执行可移动数据命令,执行完成后就可以回滚数据
alter table 表名 enable row movement;
2、正式回滚 update 语句前的数据 确定要回滚的时间点
flashback table 表名 to timestamp TO_TIMESTAMP('2017-07-21 17:16:38', 'yyyy-mm-dd hh24:mi:ss');
8、数据泵方式备份
数据库备份:
数据库导出:
expdp username/usernamedumpfile=*****.dmp DIRECTORY='DATA_PUMP_DIR' full=y
数据库导入:
impdp username/username@orcle directory=DATA_PUMP_DIR dumpfile=*****.dmp TABLE_EXISTS_ACTION=REPLACE remap_schema=username:username remap_tablespace=user1_space :user1_space full=y