Here are four ways to get the data type of a column in MySQL.
Continue readingCategory: Relational
Return Random Rows from a Table in MariaDB
Here’s a quick way to return random rows from a table in MariaDB.
Continue readingHow to Format Numbers with Commas in SQL
Most of the major RDBMSs have functions that enable us to format numbers with commas as either the group separator, or the decimal separator.
Some RDBMSs also output certain numeric data types with commas in the relevant place.
Below are examples of formatting numbers with commas in some of the more popular DBMSs.
Continue readingDATABASE() – Get the Current Database Name in MySQL
In MySQL, DATABASE()
is a built-in function that returns the default (current) database name.
The result is returned as a string in the utf8
character set. If there is no default database, it returns NULL
.
PRAGMA table_list in SQLite
In SQLite, the table_list
pragma returns information about the tables and views in the schema.
It was first introduced in SQLite version 3.37.0 (released on 2021-11-27).
Continue reading3 Ways to Get a List of Databases in SQL Server (T-SQL)
Below are three ways we can use T-SQL to return a list of databases in SQL Server.
Continue readingDROP TABLE IF EXISTS in MariaDB
In MariaDB, we can use the IF EXISTS
clause of the DROP TABLE
statement to check whether the table exists or not before dropping it.
SUM() Function in MySQL
In MySQL, the SUM()
aggregate function returns the sum of a given expression.
It can also be used to return the sum of all distinct (unique) values in an expression.
Continue readingFix “Arithmetic overflow error converting int to data type numeric” in SQL Server
If you’re receiving error Msg 8115, Level 16, Arithmetic overflow error converting int to data type numeric in SQL Server, it’s probably because you’re performing an operation that results in a data conversion error due to an out of range value.
This will often happen when you try to convert a number to a different data type, but it’s out of the accepted range for the new data type.
Continue readingFix “Arithmetic overflow error converting expression to data type int” in SQL Server
If you’re receiving error Msg 8115, Level 16, Arithmetic overflow error converting expression to data type int in SQL Server, it could be that you’re performing a calculation that results in an out of range value.
This can happen when you use a function such as SUM()
on a column, and the calculation results in a value that’s outside the range of the column’s type.