logo

Stavek Oracle ALTER TABLE

V Oraclu stavek ALTER TABLE določa, kako dodati, spremeniti, izpustiti ali izbrisati stolpce v tabeli. Uporablja se tudi za preimenovanje tabele.

Kako dodati stolpec v tabelo

Sintaksa:

 ALTER TABLE table_name ADD column_name column-definition; 

primer:

uml diagram java

Upoštevajte, da že obstoječe stranke tabele. Zdaj dodajte nov stolpec customer_age v tabelo customer.

 ALTER TABLE customers ADD customer_age varchar2(50); 

Zdaj bo v tabelo strank dodan nov stolpec 'customer_age'.

Kako dodati več stolpcev v obstoječo tabelo

Sintaksa:

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

Primer

 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. 

Kako spremeniti stolpec tabele

Sintaksa:

 ALTER TABLE table_name MODIFY column_name column_type; 

primer:

vsebuje podniz java
 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. 

Kako spremeniti več stolpcev v tabeli

Sintaksa:

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

primer:

 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. 

Kako spustiti stolpec tabele

Sintaksa:

 ALTER TABLE table_name DROP COLUMN column_name; 

primer:

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

Kako preimenovati stolpec tabele

Sintaksa:

niz bajtov v niz
 ALTER TABLE table_name RENAME COLUMN old_name to new_name; 

primer:

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

Kako preimenovati tabelo

Sintaksa:

 ALTER TABLE table_name RENAME TO new_table_name; 

primer:

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