SQL Code Snippets


I strongly recommend owning / reading Sam's Teach Yourself SQL in 10 Minutes. It's the only book on a programming language that I recommend actually owning a copy of.

Delete a Table

Deletes my_table and all of its data.

Delete Rows that Satisfy a Condition

Deletes all rows in my_table that have a column_b value equal to -3.

Update Rows that Satisfy a Condition

Updates all rows in my_table with column_b equal to 5so that their column_a now equals 'no longer cool' and column_b now equals -3.

Get Rows that Satisfy a Condition

Retrieves column_a and column_b of every row in my_table which has a column_a value equal to 'this is cool'.

Get Certain Columns of Every Row

Retrieves column_a and column_b of every row in my_table.

Get Every Column of Every Row

Retrieves every column of every row in my_table.

Insert a Row

Adds data to my_table. This statement would still function with column_a and 'this is cool' removed, since column_a can be NULL (see below).

Create a Table

Creates a new table called my_table, asuming it does not already exist. column_a can contain strings up to 500 characters in length or NULL. And, column_b can only contain integers.