πŸ’» Programming/Oracle 11g

Rename을 μ΄μš©ν•œ ν…Œμ΄λΈ” λ°±μ—… ( Table Backup using Renaming )

μΌ€μ΄μΉ˜ 2015. 4. 14. 15:38

ν…Œμ΄λΈ” 백업을 ν• λ•Œμ— export / import λ₯Ό μ΄μš©ν•  μˆ˜λ„ μžˆμ§€λ§Œ λ‹¨μˆœν•˜κ²Œ rename λͺ…λ Ήμ–΄λ₯Ό μ΄μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. λ˜ν•œ create ~ as select ~ λ₯Ό μ΄μš©ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

ν•˜μ§€λ§Œ μ˜€λŠ˜μ€ ν…Œμ΄λΈ” λͺ…을 λ³€κ²½ν•˜κ³  μƒˆλ‘œ ν…Œμ΄λΈ”μ„ μƒμ„±ν•¨μœΌλ‘œμ¨ 백업을 ν•  수 μžˆλŠ” 방법을 μ†Œκ°œν•˜λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€. 참고둜 이 방법은 blob데이타가 λ§Žμ€ κ²½μš°μ— μƒλ‹Ήνžˆ μœ μš©ν•©λ‹ˆλ‹€.


Step by Step

1) Query table name and index names linked to the table you want to backup

2) Rename table name

3) Rename indexes' name ( if specified explicitly when it is created )

4) Rename constraints' name ( if specified explicitly when it is created )

4) Use the same DDL used to create the renamed table


β€» This way is very simple and fast then using "create table ~ as select * from ~" statement when the table has a huge blob data.



1) λ³€κ²½ν•˜κ³ μžν•˜λŠ” ν…Œμ΄λΈ”μ— μ–΄λ–€ μΈλ±μŠ€λ“€μ΄ μžˆλŠ”μ§€ μ‘°νšŒν•©λ‹ˆλ‹€.

SQL > select index_name, table_name from user_indexes;


2) ν…Œμ΄λΈ”λͺ…을 λ³€κ²½ν•©λ‹ˆλ‹€.

SQL > rename old_table to new_table;


3) 인덱슀λͺ…을 λ³€κ²½ν•©λ‹ˆλ‹€. ( 인덱슀λͺ…이 μžλ™μƒμ„±λœ 것이 μ•„λ‹Œ κ²½μš°μ—λ§Œ )

SQL > alter index pk_old_table rename to pk_new_table;


4) μ œμ•½μ‚¬ν•­λͺ…을 λ³€κ²½ν•©λ‹ˆλ‹€. ( μ œμ•½μ‚¬ν•­λͺ…이 μžλ™μƒμ„±λœ 것이 μ•„λ‹Œ κ²½μš°μ—λ§Œ )

SQL > select * from user_cons_columns where table_name='{table_name};

SQL > alter table {table name} rename constraint {constraint name} to {new constraint name}


5) κΈ°μ‘΄ ν…Œμ΄λΈ”μ„ μƒμ„±ν–ˆλ˜ DDL을 μ‚¬μš©ν•˜μ—¬ ν…Œμ΄λΈ”μ„ μƒˆλ‘œ μƒμ„±ν•©λ‹ˆλ‹€.

SQL > create table .........