SQL Structure and Syntax

 < Day Day Up > 

You'll find SQL simple to learn and use if you know the proper syntax for passing data. For the most part, SQL consists of keywords individual words with a predefined meaning. Most keywords can include arguments, just like functions and procedures. A keyword with arguments is known as a clause.

Combined clauses that make a request of the database engine are called statements. A statement can consist of just one clause, but usually, there is more than one.

The most basic and general statement form is the following:

 

 action fieldlist FROM datasource 

where action is one of many keywords that defines the statement's purpose, fieldlist defines the fields to act upon, and datasource identifies the table in which the data is stored.

You can limit the records acted upon by adding a WHERE clause in the form

 

 action fieldlist FROM datasource [WHERE condition] 

Table A.1 lists the most common action SQL keywords. Table A.2 lists several SQL keywords that act as predicates that supply more information to the statement.

Table A.1. Common SQL action Keywords

Keyword

Purpose

Syntax

SELECT

Retrieve data

SELECT fieldlist FROM datasource

UPDATE SET

Modify data

UPDATE datasource SET col = expression

DELETE

Delete records

DELETE FROM datasource

INSERT INTO

Insert (or append) records into any existing table

INSERT INTO target SELECT datasource

SELECT INTO

Copy an existing table's structure and data to a new table

SELECT fieldlist INTO newtable FROM datasource


Table A.2. Additional Information Keywords and Predicates

Keyword

Purpose

Syntax

ALL

Predicate that retrieves or acts upon all the rows in the data source

SELECT ALL FROM datasource

DISTINCT

Predicate that returns unique values in specified fields

SELECT DISTINCT fieldlist FROM datasource

DISTINCTROW

Predicate that returns unique records

SELECT DISTINCTROW fieldlist FROM datasource

FROM

Identifies the data source

FROM datasource

TOP

Limits the number of records retrieved or acted upon

TOP number

WHERE

Condition expression that conditionally limits records

WHERE conditionalexpression

GROUP BY

Arranges records by similar values

GROUP BY fieldlist

ORDER BY

Sorts records by a field or fields

ORDER BY fieldlist

HAVING

Determines which records make it to a group

HAVING condition


     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net