I created the following table
CREATE TABLE PLACE( POSTCODE VARCHAR(10) PRIMARY KEY, STREET_NAME VARCHAR(10), COUNTY VARCHAR(10), CITY VARCHAR(10));
I want to change the name
, county
and city
from varchar(10)
to varchar(20)
. How do I do that?
Oracle will allow you to modify data types on existing columns in an existing table where there is already data, as long as the existing data is compatible with the new data type.
We can use ALTER TABLE ALTER COLUMN statement to change the datatype of the column. The syntax to change the datatype of the column is the following. In the syntax, Tbl_name: Specify the table name that contains the column that you want to change.
The ALTER COLUMN command is used to change the data type of a column in a table.
ALTER TABLE place MODIFY( street_name VARCHAR2(20), county VARCHAR2(20), city VARCHAR2(20) )
Note that I am also changing the data type from VARCHAR
to VARCHAR2
to be more conventional. There is no functional difference at present between the two though the behavior of VARCHAR
may change in the future to match the SQL standard.
if you want to change only type of column use below:
ALTER TABLE <table_name> MODIFY (<column_name> <new_Type>) in your case: ALTER TABLE place MODIFY (street_name VARCHAR2(20), county VARCHAR2(20), city VARCHAR2(20))
If your table has data you could act below:
For rename a column use below:
ALTER TABLE <table_name> rename column <column_name> to <new_column_name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With