Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change existing column type of a table in Sybase?

I searched for a while and can't get an answer.

Why this doesn't work? ALTER TABLE mytable ALTER COLUMN price DOUBLE

like image 867
Ziyang Zhang Avatar asked Jun 28 '12 18:06

Ziyang Zhang


People also ask

Can we modify a data type of a column which contains data in it?

In addition, you can change most data types when a field contains data. However, depending on the original data type and the new data type that you want to use, Access might truncate or delete some data, or it may not allow the conversion at all.

How can I get table column names and data types in Sybase?

You can use built-in procedure sp_columns. It will return all the table metadata including column name, data type, column length etc. for a given table.

Can we alter column type in SQL?

The ALTER COLUMN command is used to change the data type of a column in a table.


2 Answers

The syntax is incorrect and there is no DOUBLE datatype in Sybase.

So, you may try it like this:

ALTER TABLE mytable MODIFY price float
like image 190
aF. Avatar answered Oct 16 '22 18:10

aF.


To alter any table in order to change the datatype of some field :
ALTER TABLE <table_name> MODIFY <column_name> <new_datatype>
For example:
In order to change the datatype of any column 'emp_id' from int to varchar, you need to :
ALTER TABLE employee MODIFY emp_id varchar(10)
Isn't it simple ?

like image 42
Satyendra Avatar answered Oct 16 '22 18:10

Satyendra