Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table with one columns of integer data type. I want to add another columns with string data type.
Finally I want to copy the values in first column to the second columns.
That means I want to copy the integer data from column one and copy that to second column in string format.
Casting the column to a CHAR will do what you want:
UPDATE `table` SET column2 = CAST(column1 AS CHAR)
Use ALTER TABLE to add columns. Syntax for adding is
ALTER TABLE tablename ADD column_name datatype;
To transfer:
UPDATE tablename SET second_column = CAST(first_column AS CHAR);
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to add a computeed column.
alter table datatest add column amount2 double as (amount*rate)
but I got error while executing this
MySQL doesn't support computed columns prior to MySQL 5.7. The more recent versions do now support computed columns.
You can use a view instead:
create view v_datatest as
select t.*, (amount * rate) as amount2
from datatest;
Notes:
In databases that do support computed columns, the type is not part of the column definition. It is derived from the expression (you can use cast()/convert() to convert to a particular type).
It is a bad idea to store monetary amounts using floating point representations. You should be using decimal/numeric instead.
If you don't want to use a view, you can add a column to the table (along with the type) and use a trigger to maintain the value.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Is it possible to get a particular updated column name from a record?
if so, please help me. since i am creating a history table to store a updated column and their values from rest of the tables.
Please suggest me a correct way to deal this....
I believe it is not possible.
However, you can create an update trigger which monitors the table's columns and have that trigger insert records in your history table. Hope this helps.
The only way for doing this is Using something like a Log file, in this case you will create a table that will contains the updated columns each time there is an update.
In this way you will be able to get the last record that will contains the table_name and the column_name.
And you can use a query looks like that:
select id, column_name, table_name
from Log_table
order by id desc
limit 1
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I need to update the value of a column in a db table substituting part of a path.
My current path is:
software-features/adadadad.html
It should become:
software/adadadad.html
I need an sql update statement (valid for MySQL 5.5) that changes just a part of the value of a column
Is this what you want?
update t
set path = replace(path, 'software-features', 'software')
where path like 'software-features%';
The "replace" function would seem to do what you want, but it's unclear from your question how specific or generalized the solution you're looking for is:
UPDATE MyTable
SET path = REPLACE(path, "software-features/", "software/")
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I've got a large database table and wanting to select rows in the column 'cat_id' containing the value "79", then replace all the values in a column called "system" with the value "6" for the selected rows.
This query will do that:
UPDATE `table` SET `system` = '6' WHERE `cat_id` = '79'
I could be misunderstanding you, but i think you are looking for a simple update:
UPDATE yourTable
SET system = 6
WHERE cat_id = 79;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i have a mysql table with fields:
appName appVersion
i want to insert content into this fields if combination of appName and appVersion not exist in it.
In MySQL you have an option:
Create unique index by 2 columns appName, appVersion
Use INSERT IGNORE - this will skip INSERT if the corresponding record already exists in table