Entries in the ‘MySQL’ Category:

Careful with Numeric Data Types in MySQL

TINYINT can be set to length of 4, but that doesn’t mean the max value is 9999. A tiny int will always have the same range no matter what size you specify since that isn’t what it is for with integers. It is the display width for the command line output.
This is what I was [...]

Conditions on Count or Sum in MySQL

When selecting count, sum, or some other aggregate function, the value isn’t determined until after the WHERE clause so a condition can’t be placed there. There is still syntax for specifying a condition for this, it is to use HAVING.
The following example is to count all of the logs an active user has made only [...]

Tips for MySQL to PostgreSQL Switch

If you’ve decided to move a few tables from MySQL to PostgreSQL, these few tips might help. I won’t get into any reasons why to move to PostgreSQL or not. There are already
many discussions on
the topic.
Create Syntax
The first five listed need to be done in order; the rest can be in any.

Replace mediumint [...]

How To Use Triggers to Track Changes in MySQL

Setting constraints and rules in the database is better than writing special code to handle the same task since it will prevent another developer from writing a different query that bypasses all of the special code and could leave your database with poor data integrity.

addthis_url = ‘http%3A%2F%2Fcodespatter.com%2F2008%2F05%2F06%2Fhow-to-use-triggers-to-track-changes-in-mysql%2F’;
addthis_title [...]

Swap Insert for Update When Key Exists

When synchronizing tables or databases, sometimes it is useful to have a way to update a row if there is already an entry for a key. Using the MySQL syntax, ON DUPLICATE KEY UPDATE, it is possible to insert a row if it doesn’t exist or update it if there is already a row with [...]