Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alter the size of column in table containing data [duplicate]

Tags:

sql

oracle

Possible Duplicate:
How to make a varchar2 field shorter in Oracle?

In Oracle(9i and above)

 Alter table employee    MODIFY ename varchar2(10); 

I want to alter the column ename of table employee from varchar2(30) to varchar2(10)

  • Case1 : if the table has data having ename column containing values which are of length less than 10 char(i mean it can fit in varchar2(10) comfortably) - is this allowed by oracle ?

  • Case 2: if the table has data having ename column containing values which are of length greater than 10 char(i mean it can not fit in varchar2(10)) - is this not allowed by oracle ?

like image 989
lowLatency Avatar asked Apr 16 '12 18:04

lowLatency


People also ask

Can we decrease size of column if it has data in it?

it is not possible to decrease the size of column. same table it is not possible.

How do you modify the size of a column?

In generic terms, you use the ALTER TABLE command followed by the table name, then the MODIFY command followed by the column name and new type and size. Here is an example: ALTER TABLE tablename MODIFY columnname VARCHAR(20) ; The maximum width of the column is determined by the number in parentheses.

How do you change the size of a column in Oracle?

SQL - Modify Column Data Type and SizeALTER TABLE Employee ALTER COLUMN FirstName VARCHAR(50); The following will change the size in the Oracle database. ALTER TABLE Employee MODIFY (FirstName VARCHAR2(50)); The following will change the size in the PostgreSQL database.

How do I change the size of a column in SQL?

In this case, you need to use ALTER TABLE statement to increase column size. ALTER TABLE table_name MODIFY column_name varchar(new_length); In the above command, you need to specify table_name whose column you want to modify, column_name of column whose length you want to change, and new_length, new size number.


1 Answers

Case 1 : Yes, this works fine.

Case 2 : This will fail with the error ORA-01441 : cannot decrease column length because some value is too big.

Share and enjoy.

like image 72