Category: Databases

Group concatenation in T-SQL using CTE

In Oracle you have listagg() and in MySQL you have group_concat() to create string aggregations. But what do you have in T-SQL? The simple answer is nothing, yet, and we’re all hoping for a change in the future. But until then it’s up to us to do it by hand. In a previous post I




How to use recursive CTE calls in T-SQL

A common table expression (CTE) in T-SQL is used by many to get around the internal referencing problem in derived tables. It also gives you a better overview of your query compared to having nested derived tables. But one really nice feature with CTEs is that you can let it call itself recursively and nest




Create your own MySQL query profiler in PHP

Do you know how many times your PHP scripts are calling the database or how long time the queries take to execute? Maybe it’s time to create your own query profiler? It’s simpler than you might think. There are several ways of doing it but we’ll look into one example here based upon a previous




How to automatically recover from an MySQL SERVER HAS GONE AWAY error

The error message is very self explaining – the program lost connection to the server. The reason for this error is quite often simply that the script took longer time to execute than the time-out settings in the connection. In PHP there is a simple command to check if the database connection still is open:




Converting BLOB in MySQL

Blob is a format used in MySQL to hold binary data (binary large objects). Blobs are treated as binary strings but has no character set information. Normal text is treated as character strings with character set information stored. If you want to use a blob you therefore have to know what character set it’s coded




%d bloggers like this: