SQL 1
SQL 1
Programming
Structured Query Language
1
Primary Key of a Table
2
Introducing the Structured Query
Language
Structured Query Language (SQL) is a
specialized set of database programming
commands that enables the developer or other
database users to perform tasks in a database
management system. Some examples of the
types of tasks you can perform with SQL are:
3
Introducing the Structured Query
Language
Change data in tables by inserting, deleting, and
updating records.
4
Introducing the Structured Query
Language
A SQL statement contains one or more lines of
text, much like a code statement in Visual Basic.
5
Introducing the Structured Query
Language
6
Introducing the Structured Query
Language
Note
7
Using the SELECT Statement
The SELECT statement is the most frequently
used SQL command. It retrieves records (or
specified fields from records) from one or more
tables in the database. The SELECT statement,
take the following general form:
8
Using the SELECT Statement
The simplest, most common example of a
SELECT statement is selecting all fields from a
single table. To display all of the data in the
person table, execute the following SELECT
statement:
9
Using the SELECT Statement
Person Table
10
Using the SELECT Statement
Note
11
Choosing the Field List
In the field list portion of a SELECT statement,
you can specify the asterisk (*) or a list of specific
field names. The asterisk indicates that you want
to display all fields in the table. If you want to
display only certain fields, you need to include a
comma-separated list of fields, as in the
following example:
12
Choosing the Field List
13
Choosing the Field List
In general, it is a good programming practice to
specify a field list whenever possible, rather than
just using asterisk, for the following reasons:
15
Filtering the Records
16
Filtering the Records
To return only the names of the Smiths in the
Person table, you could execute the following
SELECT statement:
18
Filtering the Records
19
Filtering the Records
To return the names, ages and addresses
of the persons in the Person table who live
in city Dallas, you could execute the
following SELECT statement:
20
Filtering the Records
21