Microsoft Office Tutorials and References
In Depth Information
Manipulating Databases with SQL
SQL provides a rich collection of statements for manipulating data in a relational database.
In practice, most of these statements apply to creating or modifying tables or other database
objects stored in the database, which leaves only four main statements that the average pro­
grammer really needs to understand in order to write database programs.
The Select statement specifies the rows of data you want to retrieve from the database.
The Delete statement specifies the rows of data you want to remove from the database.
The Insert statement specifies the rows of data that you want to add to the database.
The Update statement specifies how to change existing rows of data in the database.
For instance, here’s a Select statement that retrieves some rows of customer information:
Select CustomerId, Name, City, State
From Customers
Where State = ’WA’
This Select statement returns a set of rows that contains four columns, CustomerId, Name ,
City , and State , all from the Customers table. However, instead of returning every row in the
table, only the rows where the State column contains the string ‘ WA ’ are returned. The other
statements are equally easy to use. The statements have a number of common clauses, which
means that if you know how to use one of the statements, learning how to use the others will
be a straightforward process.
Note Although the SQL language is an international standard, each database vendor is
free to add extensions to the language. What this generally means is that the exact syntax
of the SQL language will vary from one database to another. For the most part, these differ€
ences aren’t important, especially if you stick to the core syntax.
The Select Statement
The Select statement is used to retrieve a set of rows from one or more tables and is probably
the most commonly used statement in the SQL language. Here is its syntax:
Select <selectexpression> [,<selectexpression>]…
From <tableref> [,<tableref>]…
[Where <expression>]
[Order By <expression> [Asc|Desc] [, <expression> [Asc|Desc] ] …
Where
<selectexpression> ::= * |
<selectitem> [ [As] <alias> ]
<selectitem> ::= <column> |
<table>.<column> |
<tablealias>.<column>
<expression> |
<function> ( <expression> )
Search JabSto ::




Custom Search