Powered by Cellfex RSS Follow me on Spotify

Archive for the ‘MySQL’ Category

All those Mac users who enjoy free services of SequelPro – recently export was improved in a very very very good way. Now you can export tables and select explicitly if you want to export either structure, data or both for every single table in db.

Makes life so much easier.

7 Sep 2011

Sequel Pro export improved

Author: Edgars | Filed under: DailyStuff, Mac, MySQL

If you want to update every second row (actually its updating odd and even rows in MySQL table) then this is a small trick i found on one 7 years old printout.
So the problem with me was that i accidentally updated one enum column on all rows so this table…
+---+---+
| 1 | A |
| 2 | b |
| 3 | A |
| 4 | b |
| 5 | A |
+---+---+

…turned out to have B’s everywhere, but i just wanted to capitalize them where they are…
+---+---+
| 1 | B |
| 2 | B |
| 3 | B |
| 4 | B |
| 5 | B |
+---+---+

…first i got depressed (because manually changing 1000 rows wasnt included in todays plans), so i remember i had something similar many years ago and guess what – found it. Solution was to use mod() to detect if row id was odd or even…
update `table1` set value='A' where MOD(id,2) = 1;
update `table1` set value='B' where MOD(id,2) = 0;

… and voila! my day (night, actually) is saved…
+---+---+
| 1 | A |
| 2 | B |
| 3 | A |
| 4 | B |
| 5 | A |
+---+---+

Of course, it doesnt help you if id’s are mixed or even more sad – no id’s at all. Well, if you know better solution – would be appreciated.

30 Jul 2010

MySQL Update every second row

Author: Edgars | Filed under: DailyStuff, MySQL, Web Development

Well, this one of those cases, where “bug” is called “feature“. Or in this case “documented limitation“.

Problem is – MySQL Datetime field does not accept default NOW(). Which should be logic and selbstverstandlich. Read the rest of this entry »

2 Apr 2010

MySQL Datetime field does not accept default NOW()

Author: Edgars | Filed under: MySQL

There are few common (I’m not talking about all o them, just frequently used) types of data storage in MySQL – texts for texts, integers for integers and blobs for binary data.

So of course, you can always use the largest available, but speaking in terms of efficiency, how do you decide which one of them to use? By max size of content stored there. Read the rest of this entry »

1 Apr 2010

How to select correct storage data type in MySQL

Author: Edgars | Filed under: MySQL, Web Development