How to Create a Table Only if it Doesn’t Exist in SQLite

In SQLite, you can use the IF NOT EXISTS clause of the CREATE TABLE statement to check whether or not a table or view of the same name already exists in the database before creating it.

Creating a table without this clause would normally result in an error if a table of the same name already existed in the database. But when using the IF NOT EXISTS clause, the statement has no effect if a table already exists with the same name.

Continue reading

How to Check a Column’s Data Type in SQL

In SQL, the columns information schema view, which returns information about columns, is an ISO standard view that is supported by most of the major RDBMSs. You can use this view to get information about a column’s data type.

Most of the major RDBMs also provide other methods for getting column information.

Here are examples of getting the data type of a column in various SQL databases.

Continue reading