ite115 – unit 7-access: inventory database frequently...

15
Professor: Michael Torres - [email protected] (Updated 04/2019) Page | 1 ITE115 – Unit 7-Access: Inventory Database Frequently Asked Questions (FAQ) Note: These resources are designed to help you complete the 7.2 Access Database Assignment. This is intended to augment, not replace, ITE115 Course resources or independent research. Please let me know if you have any question. Table of Contents Access and SQL Terminology ................................................................................................................................................. 2 What are Access SQL basic concepts, vocabulary, and Syntax for creating Queries? ........................................................ 2 SQL Tutorials........................................................................................................................................................................... 2 SQL Query Tutorials................................................................................................................................................................ 2 Building Tables ....................................................................................................................................................................... 3 What are Field Data Types and which should you use? ..................................................................................................... 3 How do I establish relationships between tables using Primary and Foreign Keys? .......................................................... 3 Building Queries ..................................................................................................................................................................... 4 How do I create SQL Queries in MS Access?....................................................................................................................... 4 What are components of a SQL Statement? ...................................................................................................................... 4 What are SQL Statement Clauses (FROM, WHERE, GROUP BY, ORDER BY, HAVING, etc…)? ............................................ 4 What is the SQL Statement Clause and Operator order of execution? .............................................................................. 4 What is the SQL Statement SELECT syntax? ....................................................................................................................... 4 What are SQL Statement Operators? ................................................................................................................................. 4 What are SQL Statement Predicates? ................................................................................................................................. 4 How to use AND, OR, NOT operators in SQL Statements to perform a query? ................................................................. 4 What are and when should I use SQL JOIN Statements to combine data or rows from two or more tables? (INNER/OUTER JOIN, LEFT/RIGHT JOIN, and FULL JOIN) .................................................................................................... 5 How to build a query to reference a single table and joining multiple tables (with table field names with and without spaces)?............................................................................................................................................................................... 5 What is the difference between GROUP BY and ORDER BY? ............................................................................................. 6 What are SQL Alias (Using the AS keyword)? ..................................................................................................................... 7 How create a Calculated SQL Alias, with the ‘AS’ operator, using Arithmetic (Mathematical) Operators? ...................... 7 How to do mathematical calculations in SQL Queries with Mathematical Operators and Functions?.............................. 8 How to use Aggregate Functions (i.e., COUNT, Minimum (MIN), Maximum (MAX), and Average (AVG))? ...................... 8 How do you create SQL Alias that aggregates results with MIN, MAX, and AVG functions? ............................................. 8 7.2 Assignment Access Database - Final Product Walkthrough ........................................................................................... 9 What should your Access Database assignment look like when you are done? ................................................................ 9

Upload: others

Post on 30-Jun-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 1

ITE115 – Unit 7-Access: Inventory Database Frequently Asked Questions (FAQ)

Note: These resources are designed to help you complete the 7.2 Access Database Assignment. This is intended to augment, not replace, ITE115 Course resources or independent research.

Please let me know if you have any question.

Table of Contents Access and SQL Terminology ................................................................................................................................................. 2

What are Access SQL basic concepts, vocabulary, and Syntax for creating Queries? ........................................................ 2

SQL Tutorials ........................................................................................................................................................................... 2

SQL Query Tutorials ................................................................................................................................................................ 2

Building Tables ....................................................................................................................................................................... 3

What are Field Data Types and which should you use? ..................................................................................................... 3

How do I establish relationships between tables using Primary and Foreign Keys? .......................................................... 3

Building Queries ..................................................................................................................................................................... 4

How do I create SQL Queries in MS Access? ....................................................................................................................... 4

What are components of a SQL Statement? ...................................................................................................................... 4

What are SQL Statement Clauses (FROM, WHERE, GROUP BY, ORDER BY, HAVING, etc…)? ............................................ 4

What is the SQL Statement Clause and Operator order of execution? .............................................................................. 4

What is the SQL Statement SELECT syntax? ....................................................................................................................... 4

What are SQL Statement Operators? ................................................................................................................................. 4

What are SQL Statement Predicates? ................................................................................................................................. 4

How to use AND, OR, NOT operators in SQL Statements to perform a query? ................................................................. 4

What are and when should I use SQL JOIN Statements to combine data or rows from two or more tables? (INNER/OUTER JOIN, LEFT/RIGHT JOIN, and FULL JOIN) .................................................................................................... 5

How to build a query to reference a single table and joining multiple tables (with table field names with and without spaces)? ............................................................................................................................................................................... 5

What is the difference between GROUP BY and ORDER BY? ............................................................................................. 6

What are SQL Alias (Using the AS keyword)? ..................................................................................................................... 7

How create a Calculated SQL Alias, with the ‘AS’ operator, using Arithmetic (Mathematical) Operators? ...................... 7

How to do mathematical calculations in SQL Queries with Mathematical Operators and Functions?.............................. 8

How to use Aggregate Functions (i.e., COUNT, Minimum (MIN), Maximum (MAX), and Average (AVG))? ...................... 8

How do you create SQL Alias that aggregates results with MIN, MAX, and AVG functions? ............................................. 8

7.2 Assignment Access Database - Final Product Walkthrough ........................................................................................... 9

What should your Access Database assignment look like when you are done? ................................................................ 9

Page 2: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 2

Access Database Structure: ............................................................................................................................................ 9

Products Table: ............................................................................................................................................................. 10

Suppliers Table: ............................................................................................................................................................ 11

Products Form: ............................................................................................................................................................. 11

Products Table: ............................................................................................................................................................. 12

Art and North America Query: ..................................................................................................................................... 12

Carving Products Query: .............................................................................................................................................. 13

Category Stats Query: .................................................................................................................................................. 13

Extended Price Query: .................................................................................................................................................. 13

Large Price Query: ........................................................................................................................................................ 14

Low Stock Query: .......................................................................................................................................................... 14

Names and Categories Query: ..................................................................................................................................... 14

Products and Suppliers Query: .................................................................................................................................... 15

Access and SQL Terminology What are Access SQL basic concepts, vocabulary, and Syntax for creating Queries? Here is a link that explains concepts needed to create Access DB and SQL statements. You can also refer to Assignment 7.1 for additional information.

• https://support.office.com/en-us/article/access-sql-basic-concepts-vocabulary-and-syntax-444d0303-cde1-424e-9a74-e8dc3e460671

• https://www.w3schools.com/sql/sql_syntax.asp

SQL Tutorials Here are a couple of additional tutorials to help you write the SQL statements for your Access HW assignment.

• https://beginner-sql-tutorial.com/sql.htm • https://www.w3schools.com/sql/default.asp • https://beginnersbook.com/2018/11/introduction-to-sql/

SQL Query Tutorials • https://docs.microsoft.com/en-us/sql/t-sql/queries/queries?view=sql-server-2017

Page 3: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 3

Building Tables In addition to what is described below, please keep the following in mind:

• Table structure Note: 1) Table Field name is the same as Table Column name; 2) Field name references are case sensitive.

• Best Practice: While it is allowed, field names should not include spaces because some legacy applications cannot support field name references with spaces. That said, it is possible to use field names with spaces.

What are Field Data Types and which should you use? • https://docs.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-2017 • https://www.w3schools.com/sql/sql_datatypes.asp

How do I establish relationships between tables using Primary and Foreign Keys? After you create the Products and Suppliers Tables, but before you add the data to the tables, per the instructions in 7.2 Instructions Document,

1. This is done on the ‘Database Tools’ tab, in the ‘Relationships’ group, click ‘Relationships’. 2. In the ‘Relationships’ view tab, Right click and select ‘Show table’ and add both suppliers table and products

table. 3. In the ‘Relationships’ view tab, double click the ‘Supplier ID’ in the Products table and click ‘Create New’. The

fields labels “Left” is the Supplier ID (primary key) of the suppliers table, and the fields labeled “Right” is the Supplier ID (Foreign Key) in the Products table. Here is a screenshot of what it looks like:

Here are links that explains how this is done. You can also refer to Assignment 7.1 for additional instructions on how to do this.

• https://support.office.com/en-us/article/guide-to-table-relationships-30446197-4fbe-457b-b992-2f6fb812b58f • https://docs.microsoft.com/en-us/sql/relational-databases/tables/primary-and-foreign-key-

constraints?view=sql-server-2017

When you are done, the Table relationship should look like this:

Page 4: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 4

Building Queries In addition to what is described below, please keep the following in mind:

• Best Practice: While Access accommodates for it, you should not use the exclamation point ‘!’ as a table reference with the field name (Table!FieldName). You should use a period instead (Table.FieldName). You should not use the exclamation point because it is invalid syntax outside of ACCESS.

How do I create SQL Queries in MS Access? You can create queries using two options

1. The Query Wizard found in ‘Create’ menu –Query Group – Query Wizard 2. After you create the query, if you go to SQL view you can add, modify, or delete the SQL statement that

performs the query.

What are components of a SQL Statement? • https://www.sqa.org.uk/e-learning/SoftDevRDS04CD/page_02.htm • https://www.quora.com/What-are-“SQL-statements”

What are SQL Statement Clauses (FROM, WHERE, GROUP BY, ORDER BY, HAVING, etc…)? • SQL Clauses Explained: https://db.apache.org/derby/docs/10.5/ref/rrefclauses.html

What is the SQL Statement Clause and Operator order of execution? • https://sqlbolt.com/lesson/select_queries_order_of_execution • https://www.periscopedata.com/blog/sql-query-order-of-operations

What is the SQL Statement SELECT syntax? • https://beginner-sql-tutorial.com/sql-select-statement.htm • https://docs.microsoft.com/en-us/sql/t-sql/queries/select-transact-sql?view=sql-server-2017 • https://www.w3schools.com/sql/sql_select.asp

What are SQL Statement Operators? • https://www.w3schools.com/sql/sql_operators.asp

What are SQL Statement Predicates? • https://support.office.com/en-us/article/all-distinct-distinctrow-top-predicates-24f2a47d-a803-4c7c-8e81-

756fe298ce57 • https://www.quora.com/What-is-a-predicate-in-SQL • https://www.tutorialspoint.com/sql/sql-inner-joins.htm • https://www.w3resource.com/sql/joins/perform-an-inner-join.php

How to use AND, OR, NOT operators in SQL Statements to perform a query? When creating a query, you must use the correct operators.

Here is a link that explains how to use operators in Queries. You can also refer to Assignment 7.1 for additional information.

• https://www.w3schools.com/sql/sql_and_or.asp

Page 5: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 5

For Example, in the 7.2 assignment, it asks you to create the ‘Art and North America’ query using the ‘OR’ operator. Here is an example of the SQL statement for this query.

SELECT Products.[Product Name], Products.Category FROM Products WHERE (((Products.Category)="Art") OR ((Products.[Supplier ID])=20)) ORDER BY Products.[Product Name] DESC; This is the query result for ‘Art and North America’ if you did it correctly

What are and when should I use SQL JOIN Statements to combine data or rows from two or more tables? (INNER/OUTER JOIN, LEFT/RIGHT JOIN, and FULL JOIN)

• https://www.w3schools.com/sql/sql_join.asp • https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/ • https://www.diffen.com/difference/Inner_Join_vs_Outer_Join

How to build a query to reference a single table and joining multiple tables (with table field names with and without spaces)? In addition to what is described below, please keep the following in mind:

• Query SQL Syntax Note: While it is not required, you may use the table reference with the field name (e.g. Products.ProductID) for queries when referencing a single table. However, the table reference with the field name is required when the query is referencing multiple tables.

When creating a query, you must select the table Field names you want to include in a query. This varies depending on whether you are using Fields from a single table or multiple tables.

• Query using fields one table: For field names without spaces you only need to type the exact field name in the SELECT part of the SQL Statement. For field names with spaces you must include brackets ‘[ ]’ on both sides of the field name. For example:

• Query using fields from multiple tables: The rule above about field names with spaces still apply. When using

fields from multiple tables you must include the table name and a period prior to the field name in the SELECT part of the SQL Statement. For example:

Page 6: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 6

What is the difference between GROUP BY and ORDER BY? To sort records in SQL queries, there are two methods you can use. ORDER BY and GROUP BY.

• ORDER BY alters the order in which items are returned.

• GROUP BY will aggregate records by the specified columns which allows you to perform aggregation functions on non-grouped columns (such as SUM, COUNT, AVG, etc).

For Example, in the 7.2 assignment, it asks you to create the ‘Products and Suppliers’ Query and sort the records in ascending order by Region, and within Region, by Product Name. Here is an example of the SQL statement for this query.

SELECT Products.[Product Name], Products.Category, Products.[Supplier ID], Suppliers.[Supplier Name], Suppliers.Region FROM Products INNER JOIN Suppliers ON Products.[Supplier ID] = Suppliers.[Supplier ID] ORDER BY Suppliers.Region, Products.[Product Name];

Page 7: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 7

Here are links that explains how sort records. You can also refer to Assignment 7.1 for additional instructions on how to use ORDER BY and GROUP BY.

• https://www.essentialsql.com/what-is-the-difference-between-group-by-and-order-by/ • https://www.quora.com/What-is-the-difference-between-group-by-and-order-by-in-SQL

What are SQL Alias (Using the AS keyword)? • https://www.w3schools.com/sql/sql_alias.asp • https://www.tutorialspoint.com/sql/sql-alias-syntax.htm • https://beginnersbook.com/2018/12/sql-select-as-alias/ • http://www.sqltutorial.org/sql-alias/ • https://www.studytonight.com/dbms/sql-alias.php

How create a Calculated SQL Alias, with the ‘AS’ operator, using Arithmetic (Mathematical) Operators? To create a calculated SQL Alias, it is a two-step process.

1. You define the Calculation using you must use the ‘AS’ statement and Mathematical Operators. Arithmetic (Mathematical) Operators to include + (Add), - (Subtract), * (Multiply), / (Divide), % (Percent of). You identify the fields you want to use in the calculation and place them in the order that makes mathematical sense because PEMDAS order of operations math rules apply. Then you place the appropriate operator between the fields.

2. After the calculation, you use the AS operator then define the SQL Alias you want to use.

For Example, in the 7.2 assignment, it asks you to create the ‘Extended Price’ alias that calculates UnitsInStock * UnitPrice. Here is an example of the SQL statement for this query.

Page 8: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 8

How to do mathematical calculations in SQL Queries with Mathematical Operators and Functions? • Mathematical Operators:

o https://docs.microsoft.com/en-us/sql/t-sql/language-elements/arithmetic-operators-transact-sql?view=sql-server-2017

o http://doc.nuodb.com/Latest/Content/SQL-Mathematical-Functions-and-Operators.htm • Mathematical Functions: https://docs.microsoft.com/en-us/sql/t-sql/functions/mathematical-functions-

transact-sql?view=sql-server-2017

How to use Aggregate Functions (i.e., COUNT, Minimum (MIN), Maximum (MAX), and Average (AVG))? • https://www.dyclassroom.com/mysql/mysql-aggregate-functions-count-min-max-avg-and-sum • https://www.mssqltips.com/sqlservertip/4424/max-min-and-avg-sql-server-functions/ • https://www.universalclass.com/articles/computers/sql/using-the-sum-avg-count-min-max-operators-in-

sql.htm

How do you create SQL Alias that aggregates results with MIN, MAX, and AVG functions? To create a calculated SQL Alias using MIN, MAX, and AVG, it is a two-step process.

1. Identify which Field you want to calculate MIN, MAX, or AVG. Then you please the field name between formula parenthesis (e.g. MIN(UnitPrice))

2. After the calculation, you use the AS operator then define the SQL Alias you want to use.

For Example, in the 7.2 assignment, it asks you to create the ‘Category Stats’ query that calculates minimum, maximum, and average of Unit Price. Here is an example of the SQL statement for this query.

Page 9: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 9

7.2 Assignment Access Database - Final Product Walkthrough In this Section, I show you exactly what your assignment should look like when you are done.

If the SQL Tables, Form, Report and Queries look like the screenshots below, you will earn 60pts on the assignment. What is not included here is how to do it. What should your Access Database assignment look like when you are done? Access Database Structure: When you are done, you should have in your database and it should look similar to the following

• 2 Tables: Products and Suppliers • 1 Form: Products Form • 1 Report: Suppliers and Regions Report • 8 Queries: Art and North America, Carving Products, Category Stats, Extended Price, Large Price,

Low Stock, Names and Categories, & Products and Suppliers.

Page 10: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 10

Products Table: Make Product ID the primary key and set up each field with the appropriate data type and size. Make sure you set the ‘Data Type’ to correspond with the intent of the ‘Field Name’. Design View

Datasheet View

Page 11: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 11

Suppliers Table: Make Supplier ID the primary key and set up each field with the appropriate data type and size. Make sure you set the ‘Data Type’ to correspond with the intent of the ‘Field Name’. Design View

Datasheet View

Products Form: Create a form from the Products table and name it Products. Include all the fields from the Products table in the form.

Layout View: Design View:

Page 12: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 12

Products Table: Suppliers and Regions Report Create a report from the Suppliers table and name it Suppliers and Regions. Include the Supplier Name and the Region in the report. Do not include the Supplier ID. Use Landscape Orientation for the report.

Layout View: Design View:

Art and North America Query:

Datasheet View

Page 13: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 13

Carving Products Query: Datasheet View

Category Stats Query:

Datasheet View

Extended Price Query: Datasheet View

Page 14: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 14

Large Price Query: Datasheet View

Low Stock Query: Datasheet View

Names and Categories Query:

Datasheet View

Page 15: ITE115 – Unit 7-Access: Inventory Database Frequently ...blogs.nvcc.edu/mtorres/files/2019/04/Unit7_MSAccessFAQ.pdf · •Table structure Note: 1) Table Field name is the same as

Professor: Michael Torres - [email protected] (Updated 04/2019) P a g e | 15

Products and Suppliers Query:

Datasheet View