Oracle ALTER TABLE 문

Oracle에서 ALTER TABLE 문은 테이블의 열을 추가, 수정, 삭제 또는 삭제하는 방법을 지정합니다. 테이블 이름을 바꾸는 데에도 사용됩니다.

테이블에 열을 추가하는 방법

통사론:

 ALTER TABLE table_name ADD column_name column-definition;  

예:

이미 존재하는 테이블 고객을 고려하십시오. 이제 고객 테이블에 새 열 customer_age를 추가합니다.

 ALTER TABLE customers ADD customer_age varchar2(50);  

이제 고객 테이블에 'customer_age'라는 새 열이 추가됩니다.

기존 테이블에 여러 열을 추가하는 방법

통사론:

 ALTER TABLE table_name ADD (column_1 column-definition, column_2 column-definition, ... column_n column_definition);  

 ALTER TABLE customers ADD (customer_type varchar2(50), customer_address varchar2(50));  
 Now, two columns customer_type and customer_address will be added in the table customers.  

테이블의 열을 수정하는 방법

통사론:

 ALTER TABLE table_name MODIFY column_name column_type;  

예:

 ALTER TABLE customers MODIFY customer_name varchar2(100) not null;  
 Now the column column_name in the customers table is modified to varchar2 (100) and forced the column to not allow null values.  

테이블의 여러 열을 수정하는 방법

통사론:

 ALTER TABLE table_name MODIFY (column_1 column_type, column_2 column_type, ... column_n column_type);  

예:

 ALTER TABLE customers MODIFY (customer_name varchar2(100) not null, city varchar2(100));  
 This will modify both the customer_name and city columns in the table.  

테이블의 열을 삭제하는 방법

통사론:

 ALTER TABLE table_name DROP COLUMN column_name;  

예:

 ALTER TABLE customers DROP COLUMN customer_name;  
 This will drop the customer_name column from the table.  

테이블의 열 이름을 바꾸는 방법

통사론:

 ALTER TABLE table_name RENAME COLUMN old_name to new_name;  

예:

 ALTER TABLE customers RENAME COLUMN customer_name to cname;  
 This will rename the column customer_name into cname.  

테이블 이름을 바꾸는 방법

통사론:

 ALTER TABLE table_name RENAME TO new_table_name;  

예:

 ALTER TABLE customers RENAME TO retailers;  
 This will rename the customer table into 'retailers' table.