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