1. 程式人生 > >Oracle建立使用者,授權,匯入,備份表等常見sql

Oracle建立使用者,授權,匯入,備份表等常見sql

1.建立表空間

create tablespace tablespacename
logging 
datafile 'filepath\filename.dbf'
size 256m 
autoextend on 
next 128m maxsize unlimited; 

2.查看錶空間

SELECT * FROM dba_tablespaces t, dba_data_files d WHERE t.tablespace_name = d.tablespace_name 

3.建立使用者,並設定預設表空間以及臨時表空間

create user username identified by userpassword
default tablespace usertablespace
temporary tablespace temp;

4.更改使用者密碼

alter user username identified by password;

5.刪除使用者

drop user username cascade;

4.給使用者授權

grant dba to username;--授權dba,還有connect ,resource 等角色

5.匯入資料檔案(dmp)

imp username/[email protected]:port/orcl fromuser=fromuser touser=touser file='filepath' log=logfilepath ignore=y;

6.匯出資料檔案(dmp)

exp username/
[email protected]
:port/orcl file='filename' owner=(owner)--owner表示匯出owner這個使用者的表

7.備份還原表

create table tablename_bak as select * from tablename;--備份表
delete from tablename; insert into tablename select * from tablename_bak;--還原表