开发者

phpadmin mysql change 0 to 1 in a column

开发者 https://www.devze.com 2023-01-14 23:54 出处:网络
Great site, tons of help to me so far. I have a database with 10,000+ rows. There is a col开发者_StackOverflow中文版umn ( tinyint(4) ) called ahtml.

Great site, tons of help to me so far.

I have a database with 10,000+ rows.

There is a col开发者_StackOverflow中文版umn ( tinyint(4) ) called ahtml.

I need to change ~500 of the rows for that column from 0 to 1.

I know there is a query I can run in phpmyadmin to do that instead of editing each row.

I need to change ALL of the 0's to 1's in the ahtml column.

Guidance please?


UPDATE MyTable SET ahtml = IF(ahtml=1, 0, 1);

All 1 replace with 0 and 0's replace with 1s. If you are using this answer it is very simple and perfect


You can use a WHERE clause to select which rwows you want to update. You can test your query before you run the UPDATE by doing a SELECT:

select *
MyTable 
where ahtml = 0

When you are satisfied that you are selecting the right rows, do this:

update MyTable 
set ahtml = 1
where ahtml = 0


The following will set the ahtml field of all rows to 1, where it was 0:

UPDATE your_table SET ahtml = 1 WHERE ahtml = 0;

Simply replace your_table with the real name of your table.

Note that if your ahtml is a boolean field with just 1 and 0 values, this will practically set all your ahtml values to 1. In that case, you could also do:

UPDATE your_table SET ahtml = 1;

If you want to change all the 0s to 1s and all the 1s to 0s, then you may want to first set the 0s to 2s, then set the 1s to 0s, then set the 2s to 1s:

UPDATE your_table SET ahtml = 2 WHERE ahtml = 0;
UPDATE your_table SET ahtml = 0 WHERE ahtml = 1;
UPDATE your_table SET ahtml = 1 WHERE ahtml = 2;
0

精彩评论

暂无评论...
验证码 换一张
取 消