Get the Size of a Database in MariaDB

In MariaDB, we can query the information_schema.tables table to check the size of a database.

This table returns information about the tables and views in each database on the server. We can group the results and return the aggregate amounts for each database.

Read more

Find a String within a String in SQL

Most of the major DBMSs provide us with a way to find a string within a string using SQL. By this, I mean use a SQL query to find the position of a substring within a string.

There are several SQL functions that allow us to do this, including INSTR(), LOCATE(), POSITION(), and CHARINDEX(). The function you use will depend on your DBMS, and possibly whether or not you need to specify a starting position.

Read more

How to Generate a Random Integer Within a Range in MariaDB

MariaDB includes a RAND() function that returns a random number. More precisely, it returns a DOUBLE precision floating point value v in the range 0 <= v < 1.0.

This is great, but what if you want to generate an integer within a larger range – and a range that you specify?

Fortunately, there’s an easy technique for doing this.

Read more