Structured Query Language (SQL) tutorial
The Microsoft Access database
The Access database consists of the following:
- A collection of tables to store the data. This is the heart of any database.
- A collection of queries designed to extract information from the data: You can create queries using the Query BY Example interface, or directly using SQL statements in the SQL Window.
- A collection of forms and reports designed to present the information in a user-friendly manner. Forms may also be used to enter the information.
SQL and the Access database
All components of an Access database are accessible from the tabbed Database Window. Each category of objects has its own tab. So, for example, all tables in the database can be opened from the Tables tab of the Database Window.
Since this course deals with queries, you will need to work mainly from the Queries tab. However, you may need to open some of the tables to check that your queries have given the correct result.
You will not be dealing with Forms, Reports, Data Access Pages, Macros or Modules during this course.
The Query tab
This tab contains all the queries that have been written for the database:
You can create a query in Design View or SQL View. You can also switch between these two views. This course covers queries designed in the SQL View. SQL queries are much more powerful than queries written using the query grid. Some queries can only be written using SQL.
Opening the SQL editor
To open the SQL Window,
- Switch to the Queries tab of the Database Window
- Select Create query in Design view
- Click Design (see figure below). The query grid will be displayed, with a list of tables that can be selected for the query:
We will be adding tables directly to the query through SQL statements, so do not need to add them quite yet.
- Click Close to close the Show Table dialog box. The query grid will remain open. You will also see a button labeled SQL near the top left of your screen:
- Click this button to display the SQL editor:
You should enter all SQL statements into this window.
Running a query
Once you have entered a query into the SQL window,
you can see the answer to your query by clicking the Run
button,
.