Create a Temporary Table in SQLite

When you create a table in SQLite, you can create it as a permanent table or as a temporary table.

When you create a table in a database that you’ve created, that would be a permanent table. A temporary table is created in the temp database.

To create a temporary table, you use the same syntax as creating a regular table. The difference is that you use either the TEMP or TEMPORARY keyword. You can also (or alternatively) prefix the table name with temp, which indicates that it will be created in the temporary database.

Continue reading

Get the Month Name from a Date in PostgreSQL

If you’re familiar with PostgreSQL, you might know that you can use the EXTRACT() and the DATE_PART() functions to extract the month from a date. But those functions only allow you to extract the month number.

What if you need the month name?

You can get the month name from a date by using the TO_CHAR() function. This function returns a string based on the timestamp and the template pattern you provide as arguments.

Continue reading

How to Use GOTO in SQL Server

In SQL Server, you can use GOTO to alter the flow of execution. You can use it to “jump” to another part in the T-SQL code.

The way it works is, you create a label, then you can use GOTO to jump to that label. Any code between GOTO and the label are skipped, and processing continues at the label.

GOTO statements and labels can be used anywhere within a procedure, batch, or statement block. They can also be nested.

Continue reading