Home » SQL For Programmers » Basic SQL Commands – SQL For Programmers

Basic SQL Commands – SQL For Programmers

Before we get into the specifics of the commands that can be used within a stored procedure, I think it would be helpful to review some of the more basic commands that we can use that don’t really need a whole lot of discussion.

I know I said I wasn’t going to spend a lot of time on the basics, but my research indicates that a lot of people are searching for basic sql commands and very few sites are addressing that issue specifically.

So, if this is unhelpful to you, just consider this Dave’s SEO experiment.

Basic SQL Commands

SELECTThe SELECT statement returns a set of records from a table or view.  It can be used in combination with JOIN to return a set of records that are a mashup of records from multiple tables but the end result from a programming perspective is that it looks like it came from one table.  The set of records returned can be narrowed by using the WHERE clause and the order that they are returned can be set by using the ORDER BY clause.

Most common form:
SELECT field1, field2, etc FROM tableName WHERE conditions ORDER BY listOfFields

INSERTINSERT adds new records to the table.  This can be used in combination with a sub-SELECT to insert records from another table into the current table.

Most common form:
INSERT INTO tableName(field1,field2) VALUES(value1,value2)

UPDATEThis is most often used in combination with the WHERE clause to update a record in a table.

Most common form:
UPDATE tableName SET field1=value1, field2=value2 WHERE condition

DELETEWhen you need to delete a record in your table, or a set of records, you will use the DELETE statement.

Most common form:
DELETE FROM tableName WHERE condition

WHEREThe WHERE clause specifies what set of records the operation should be performed on.  We have discussed various operators in previous posts.  The most common are: =, <>, <, >, IN, and LIKE
ININ is used with the WHERE clause to determine if the field is equal to any of the items in a list.
LIKEWe discussed this one a few posts ago.  Most are familiar with the common form, LIKE ‘%content%’ to determine if ‘content’ is in the field.  But there are other useful forms of this operator as well.  Check out the list of previous posts below.
ORDER BYMost often used with the SELECT statement (and I really can’t think of any other place it is used), this controls the order the records are returned.  Most often this is a list of fields.  By default it lists everything in ascending order.  If you want the items in descending order, use the DESC modifier.

My favorite resource for SQL syntax reference is http://www.w3schools.com/sql/.

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • SQL For Programmers – Finding IN a ListSQL For Programmers – Finding IN a List In the last SQL post, we looked at looking for content that was LIKE other content.  While this has its uses, it is limited in its ability to find more than one pattern.  So what if we […]
  • SQL CURSOR Performance – SQL For ProgrammersSQL CURSOR Performance – SQL For Programmers Last week I showed how to use the SQL CURSOR to loop through records in a database.  In that article I mentioned that you want to avoid using the CURSOR if you can because it has […]
  • SQL For Programmers – Finding a StringSQL For Programmers – Finding a String Many times in our queries, we aren't looking for an exact match.  We are looking for one string that exists in another.  There are a couple statements available to us that will allow us […]
  • Random in SQL – SQL For ProgrammersRandom in SQL – SQL For Programmers Last week I had an interesting assignment: Given a specific record, randomly retrieve three related records from the database.Naturally, as a programmer, I started looking for the SQL […]
  • SQL For Programmers – Stored Procedure BasicsSQL For Programmers – Stored Procedure Basics Now that we've established a reason for using them, let's continue with the basic syntax of the stored procedure. I think you'll find that it is not that dissimilar to writing a procedure […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.