Here are four ways to check whether or not a table exists in a MariaDB database.
MariaDB
Create a Table Only if it Doesn’t Exist in MariaDB
In MariaDB, you can use the IF NOT EXISTS clause of the CREATE TABLE statement to check whether or not a table of the same name already exists in the database before creating it.
The table will only be created if there isn’t already one with the same name.
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.
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.
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.
Subtract Microseconds from a Datetime Value in MariaDB
Here are some options for subtracting one or more microseconds from a datetime expression in MariaDB.
Add a Percent Sign to a Number in MariaDB
Below is a quick example of formatting a number as a percentage in MariaDB.
3 Ways to Separate the Year, Month, and Day from a Date in MariaDB
MariaDB has several functions that enable you to extract various date and time parts from date/time values. You can use these to separate each date/time component into its own column if required.
Below are three ways to extract the year, month, and day from a date value in MariaDB.