Oracle ALTER TABLE-instructie

In Oracle specificeert de ALTER TABLE-instructie hoe kolommen in een tabel moeten worden toegevoegd, gewijzigd, verwijderd of verwijderd. Het wordt ook gebruikt om de naam van een tabel te wijzigen.

Hoe u een kolom aan een tabel toevoegt

Syntaxis:

 ALTER TABLE table_name ADD column_name column-definition;  

Voorbeeld:

Bedenk dat al bestaande tafelklanten. Voeg nu een nieuwe kolom customer_age toe aan de tabel klanten.

 ALTER TABLE customers ADD customer_age varchar2(50);  

Nu wordt een nieuwe kolom 'customer_age' toegevoegd in de klantentabel.

Hoe u meerdere kolommen aan de bestaande tabel kunt toevoegen

Syntaxis:

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

Voorbeeld

 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.  

Hoe u de kolom van een tabel kunt wijzigen

Syntaxis:

 ALTER TABLE table_name MODIFY column_name column_type;  

Voorbeeld:

 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.  

Hoe u meerdere kolommen van een tabel kunt wijzigen

Syntaxis:

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

Voorbeeld:

 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.  

Hoe u een kolom uit een tabel kunt verwijderen

Syntaxis:

 ALTER TABLE table_name DROP COLUMN column_name;  

Voorbeeld:

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

Hoe de kolom van een tabel te hernoemen

Syntaxis:

 ALTER TABLE table_name RENAME COLUMN old_name to new_name;  

Voorbeeld:

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

Hoe de naam van een tabel te wijzigen

Syntaxis:

 ALTER TABLE table_name RENAME TO new_table_name;  

Voorbeeld:

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