Oracle ALTER TABLE nyilatkozat

Az Oracle rendszerben az ALTER TABLE utasítás határozza meg, hogyan lehet oszlopokat hozzáadni, módosítani, eldobni vagy törölni egy táblázatban. A táblázat átnevezésére is szolgál.

Oszlop hozzáadása a táblázathoz

Szintaxis:

 ALTER TABLE table_name ADD column_name column-definition;  

Példa:

Vegye figyelembe, hogy a már meglévő asztali ügyfelek. Most adjon hozzá egy új ügyfél_kor oszlopot az ügyfelek táblázathoz.

 ALTER TABLE customers ADD customer_age varchar2(50);  

Most egy új „customer_age” oszlop kerül hozzáadásra az ügyfelek táblázatához.

Több oszlop hozzáadása a meglévő táblázathoz

Szintaxis:

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

Példa

 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.  

A táblázat oszlopának módosítása

Szintaxis:

 ALTER TABLE table_name MODIFY column_name column_type;  

Példa:

 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.  

Hogyan módosíthatunk egy táblázat több oszlopát

Szintaxis:

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

Példa:

 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.  

Hogyan lehet eldobni egy táblázat oszlopát

Szintaxis:

 ALTER TABLE table_name DROP COLUMN column_name;  

Példa:

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

A táblázat oszlopának átnevezése

Szintaxis:

 ALTER TABLE table_name RENAME COLUMN old_name to new_name;  

Példa:

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

Hogyan nevezzük át a táblát

Szintaxis:

 ALTER TABLE table_name RENAME TO new_table_name;  

Példa:

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