查看用戶擁有的數據庫對象
select object_name from user_objects;
查看約束信息
select constraint_name from user_constraints;
查看用戶擁有的表
select * from tab;
或
select table_name from user_tables;
查看用戶擁有的視圖
select view_name from user_views;
查看用戶擁有的觸發器
select trigger_name from user_triggers;
查看用戶擁有的序列
select sequence_name from user_sequences;
查看用戶擁有的存儲過程
select object_name from user_procedures;
查看用戶擁有的索引
select index_name from user_indexes;
顯示當前用戶
show user;
切換用戶
conn system/bjpowernode
將用戶賦予某種角色登錄
conn scott/tiger as sysdba;
查看所有的用戶
select username from dba_users;
查看用戶擁有的權限
select * from session_privs;
常用權限
CREATE SESSION |
連接數據庫 |
CREATE TABLE |
創建表 |
CREATE VIEW |
創建視圖 |
CREATE SEQUENCE |
創建序列 |
CREATE PROCEDURE |
創建存儲過程 |
CREATE TRIGGER |
創建觸發器 |
CREATE INDEXTYPE |
創建索引 |
UNLIMITED TABLESPACE |
對表空間的使用 |
給用戶加鎖
alter user scott account lock;
給用戶解鎖
alter user scott account unlock;
修改用戶密碼
alter user scott identified by tiger123;
新建用戶
create user test1 identified by test123;
刪除用戶及相關對象
drop user test1 cascade;
給用戶授權(多個采用逗號間隔)
grant create session, create table to test1;
分配空間usres給用戶
create table t_test(id number(10), name varchar2(30))
以上出現無法創建表,主要原因在于沒有分配表空間,也就是我們新建的表不知道放到什么地方。
alter user test1 default tablespace users;
授權表空間給用戶
grant UNLIMITED TABLESPACE to test1;
● 創建用戶
create user test111 identified by test111;
● 創建表空間
create tablespace data111 datafile 'D:\share\02-Oracle\data111.dbf' size 100m;
● 將表空間分配給用戶
alter user test111 default tablespace data111;
● 給用戶授權
grant create session, create table, unlimited tablespace to test111;
● 以test111登陸建立表,tt_test
create table tt_test(id number(10));
導入和導出命令imp、exp
Exp
exp scott/tiger file=D:\EMP.DMF tables=emp,dept,salgrade
Imp
Imp scott/tiger file= D:\EMP.DMF