Reputation: 623
I have a table in mysql with just one column (no primary key), say column is like this->
Column Name
----------------
Data1
Data2
Data4
What i want to do is change "Data4" to "Data3" using java connectivity. But to change cell values, i know that command->
Alter Table <tablename> set <columnname>="something" where <someothercolumnname>="somethingelse";
but this needs atleast 2 column in table, i get the syntax error when there is just one column. So can anyone help me with correct command?
Upvotes: 0
Views: 1514
Reputation: 555
Alter query is the actual answer. But there is a silly alternate, first delete it "Data4", and then insert "Data3"
Upvotes: 0
Reputation: 1270873
You could leave the table as it is and just write your query as:
select data1, data2, data4 as data3
from tablex;
Or, if you want to rename it in the database:
ALTER TABLE <tablename> CHANGE data4 data3 varchar(255);
You need to have a data type when you do this. Change the data type to the appropriate type for the column.
Upvotes: 1
Reputation: 1874
Use update query instead of alter query. The alter will help you update the table description.
update <your table name> set columnname ='Data3' where columnname='Data4';
Upvotes: 4