DELETE (3)

테이블을 삭제하려면
SQL > drop table 테이블명;

하면 됩니다. 그런데 사실 이게 물리적으로 공간을 다시 내주는 것이 아닙니다.
오라클의 drop table관련 문서를 보면 테이블을 drop할 때 purge라는 옵션을 주지 않으면 휴지통으로 넣기만 하고 물리적인 공간은 그대로 가지고 있게 됩니다. 윈도우의 휴지통 개념과 동일하다고 보면 됩니다.

오라클이 10g에서 새롭게 추가한 '휴지통' 이라는 기능.

테이블을 DROP 하더라도 언제던지 복원할 수 있게 하고자 하는 것이고요,
윈도우의 휴지통과 같다고 보시면 됩니다.

 

휴지통에 들은 테이블을 조회.
SQL> show recyclebin;

 

휴지통의 모든 내용이 비워집니다.
SQL> purge recyclebin;

 

삭제된 테이블을 되살리고 싶다면
SQL> flashback table 테이블명 to before drop;

 

만약, 특정 테이블을 휴지통에 남기지 않고 모두 삭제하려면..
SQL> drop table 테이블명 purge;

 

purge문 없이 그냥 drop 한 후에는
SQL> purge table 테이블명;


계정 생성



create user 유저네임 identified by 패스워드;
 

권한 부여, 조회

 resource, connect 는 일반적인 것을 다 사용할 수 있다. (DDL, DML 등)




grant resource, connect to 유저네임;
grant DBA to 유저네임;

select * from dba_sys_privs where grantee='유저ID';

테이블스페이스 지정




alter user 유저네임 default tablespace 테이블스페이스명;
alter user 유저네임 temporary tablespace 임시테이블스페이스명;
 

계정 삭제

 cascade 를 명시하면 유저네임과 관련된 모든 데이터베이스 스키마가 데이터 사전으로부터 삭제되고 모든 스키마 객체도 물리적으로 삭제된다.



drop user 유저네임 cascade;


💻 Programming/Oracle 11g

[SQL] Truncate vs Drop vs Delete

DELETE

The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.

 

TRUNCATE

TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

 

DROP

The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back.  

 

 

* DROP and TRUNCATE are DDL commands, whereas DELETE is a DML command. Therefore DELETE operations can be rolled back (undone), while DROP and TRUNCATE operations cannot be rolled back.