Below are five ways to check if a table exists in a PostgreSQL database.
Continue readingAuthor: Ian
4 Ways to List All Views in MySQL
Below are four ways to list out the views in a MySQL database using SQL or the command line.
Continue readingSHOW DATABASES Equivalent in SQL Server – sp_databases
There are several ways to show a list of databases in SQL Server. Probably the easiest way is to use the sp_databases
stored procedure.
The sp_databases
stored procedure is a kind of SQL Server equivalent to the SHOW DATABASES
command that can be used with DBMSs such as MySQL and MariaDB. OK, maybe they aren’t strictly equivalents, but based on their ease of use, they could be viewed as such from a user’s perspective.
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.
Continue readingAbout the V Format Element in Oracle
When using the TO_CHAR()
function to format a number in Oracle Database, you can use the V
format element to a return a value multiplied by 10n (and if necessary, round it up), where n
is the number of 9
s after the V
.
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.
Continue readingHow to Create a Table Only if it Doesn’t Exist in PostgreSQL
In PostgreSQL, 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 no other table exists with the same name. If a table already exists with that name, a “notice” will be issued instead of an error.
Continue readingFind 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 Check if a Table Already Exists Before Creating it in MySQL
In MySQL, 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.
If the table doesn’t exist, it will be created. If it already exists, it won’t be created.
Continue readingHow to Format Numbers in SQL
Most major RDBMSs provide ways for us to format numbers using SQL. Some provide only basic formatting capabilities, while others are more advanced.
Below are examples of formatting a number in some of the more popular RDBMSs.
Continue reading