Download presentation
Presentation is loading. Please wait.
Published bySuzan Sullivan Modified over 9 years ago
1
Microsoft Access 2010 Chapter 7 Using SQL
2
Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple and compound criteria in SQL queries Use computed fields and built-in functions in SQL queries Sort the results in SQL queries Objectives Using SQL2
3
Use aggregate functions in SQL queries Group the results in SQL queries Join tables in SQL queries Use subqueries Compare SQL queries with Access-generated SQL Use INSERT, UPDATE, and DELETE queries to update a database Using SQL3 Objectives
4
Using SQL4 Project – Using SQL – pg. 418 read
5
Create a Chapter 7 folder Copy Camashaly Design database from your chapter 5 folder to the chapter 7 folder Open the database from Chapter 7 folder Click on any query Click on the view button, and choose SQL view For this chapter, we will be CREATING these in SQL view Using SQL5 Housekeeping
6
Select the fields for the query Determine which table or tables contain these fields Determine criteria Determine sort order Determine grouping Determine any update operations to be performed Using SQL6 General Project Guidelines
7
SQL – Structured Query Language Originally developed under the the name SEQUEL @ IBM in the mid-1970’s. In 1980 – renamed SQL You will be typing entries into a BLANK window.. Rather than using a design grid. Let’s get started! Using SQL7 SQL Background
8
Using SQL8 Changing the Font Size - Do page 421
9
The basic form of SQL expressions is quite simple: SELECT-FROM-WHERE The command begins with a SELECT clause, which consists of the word, SELECT, followed by a list of those fields you want to include Next, the command contains a FROM clause, which consists of the word, FROM, followed by a list of the table or tables involved in the query Finally, there is an optional WHERE clause, which consists of the word, WHERE, followed by any criteria that the data you want to retrieve must satisfy Using SQL9 SQL Commands
10
Using SQL10 Creating a New SQL Query – pages 422-426
11
To restrict the records to be displayed, include the word WHERE followed by a criterion as part of the command If the field involved is a numeric field, you simply type the value Using SQL11 Using a Criterion Involving a Numeric Field
12
A simple criterion has the form: field name, comparison operator, then either another field name or a value Using SQL12 Simple Criteria
13
Using SQL13 Using a Comparison Operator
14
If the criterion involves a text field, the value must be enclosed in single quotation marks Using SQL14 Using a Criterion Involving a Text Field
15
In most cases, the conditions in WHERE clauses involve exact matches The LIKE operator uses one or more wildcard characters to test for a pattern match – One common wildcard in Access, the asterisk (*), represents any collection of characters Do page 427-430 Using SQL15 Using a Wildcard
16
Compound criteria are formed by connecting two or more simple criteria using AND, OR, and NOT – When simple criteria are connected by the word AND, all the simple criteria must be true in order for the compound criterion to be true – When simple criteria are connected by the word OR, the compound criterion will be true whenever any of the simple criteria are true – Preceding a criterion by the word NOT reverses the truth or falsity of the original criterion Using SQL16 Compound Criteria
17
Using SQL17 Using a Compound Criterion do pg. 431-433
18
The one in the book (pg. 434) is wrong. Do this one instead and save it as Ch7q10 SELECT [Client Number], [Client Name], [Amount Paid], [Current Due], [Amount Paid] + [Current Due] AS [Total Cost] FROM [Client] WHERE [Current Due] > 0 ; Using SQL18 Using a Computed Field
19
To sort the output, you include an ORDER BY clause, which consists of the words ORDER BY followed by the sort key Do pages 436-438 Using SQL19 Sorting
20
The DISTINCT operator eliminates duplicate values in the results of a query To use the operator, you follow the word DISTINCT with the field name in parentheses Using SQL20 Omitting Duplicates When Sorting
21
Pg. 440 is incorrect So do this one instead… SELECT [Business Analyst Number] FROM [Client] ORDER BY [Business Analyst Number] ; Now add the word DISTINCT after the word SELECT. Look at the difference Save the second query as Ch7q14 Using SQL21 DISTINCT
22
SQL has built-in functions, also called aggregate functions, to perform various calculations – COUNT – SUM – AVG – MAX – MIN Using SQL22 Using a Built-In Function
23
You can assign a name to the results of a function To do so, follow the expression for the function with the word AS and then the name to be assigned to the result Using SQL23 Assigning a Name to the Results of a Function
24
Using SQL24 Using Multiple Functions in the Same Command
25
Do pages 441-443 Using SQL25 Functions
26
Grouping means creating groups of records that share some common characteristic When you group rows, any calculations indicated in the SELECT command are performed for the entire group – GROUP BY clause – to get subtotals Do pages 445-446 Using SQL26 Using Grouping
27
Many queries require data from more than one table Make sure to read the part about Aliases before doing page 451. Using SQL27 Joining Tables – pages 447-451
28
A subquery is a query within another query Using SQL28 Subqueries – page 452
29
You can add records to a table using the SQL INSERT command The command consists of the words INSERT INTO followed by the name of the table into which the record is to be inserted Next is the word VALUE followed by the values for the fields in the record – Values for Text fields must be enclosed within quotation marks Using SQL29 Using an INSERT Command
30
You can update records in SQL by using the UPDATE command The command consists of UPDATE, followed by the name of the table in which records are to be updated Next, the command contains one or more SET clauses, which consist of the word SET, followed by a field to be updated, an equal sign, and the new value Using SQL30 Using an UPDATE Command
31
You can delete records in SQL using the DELETE command The command consists of DELETE FROM, followed by the name of the table from which records are to be deleted Finally, you include a WHERE clause to specify the criteria Using SQL31 Using a DELETE Command
32
The queries on pages 455-456 are for a table we don’t have. Use these instead INSERT INTO [Business Analyst] Values ('40', 'Coleman', 'Sandra', 'ABC', 'Starkville', 'MS', '39759', 25000, 5000) ; Save this query as CH7q24 Go look at the Business Analyst table and make sure I am there! MUST SHOW ME! Using SQL32 INSERTing records in a table with SQL
33
Type the following query UPDATE [Business Analyst] SET [Incentive YTD] = 10000 WHERE [Business Analyst Number] = '40' ; Save the query as Ch7q25 Now, go check the table and see that it updated! MUST SHOW ME! Using SQL33 UPDATEing records using SQL
34
Type the following DELETE FROM [Business Analyst] WHERE [Business Analyst Number] = '40' ; Now, check the table to make sure I am gone! Save this query as Ch7q26 MUST SHOW ME! Using SQL34 Deleting Records in SQL
35
What Next? Homework www.scsite.com/ac2010 Do Flash Cards.. You get what you make Due next class meeting Labs IN THE LAB lab 3: Philamar Training database. Page 462. That’s all for SQL chapter. Your final exam will be ONLY SQL… FINAL EXAM – Wednesday, Dec. 12 @ 10:15.. 35Using SQL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.