Bookmark and Share

SQL - Queries

SQL coins the term query as the name for its commands. Basically, all SQL code is written in the form of a query statement and then executed against a database. All SQL queries perform some type of data operation such as selecting data, inserting/updating data, or creating data objects such as SQL databases and SQL tables. Each query statement begins with a clause such as SELECT,UPDATE, CREATE or DELETE.

Advertise on

SELECT queries are the most commonly used SQL commands, so let's take a look at a SELECT query that will return records from the orders table that we created previously in the SQL Tables lesson.

SQL Query Code:

USE mydatabase;

SELECT * FROM orders;

SQL Query Results:

1Tizag2008-08-01 00:00:00.000Pen4

We'll explain the mechanics of this code in the next lesson. For now, just know that SELECT queries essentially tell SQL to go and "fetch" table data for your viewing pleasure.

Here's a look at a few different query types including a INSERT and SELECT query we will be covering in the next lesson, SQL Select.

SQL Query Examples:

-- Inserts data into a SQL Database/Table
INSERT INTO orders (customer,day_of_order,product, quantity)

-- Selects data from a SQL Database/Table
SELECT * FROM orders;

-- Updates data in a Database/Table
UPDATE orders SET quantity = '6'
WHERE id = '1'

More information about these queries can be found at the following links: SQL Insert, SQL Update, SQL Delete

SQL - Query Structure Review

Structurally, each SQL query we have seen in this lesson are similar. Each start with a clause telling SQL which operation to perform and the remaining lines provide more detailed information as to how we want SQL to go about performing each SQL Command.

Bookmark and Share

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials