* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download ppt
Survey
Document related concepts
Functional Database Model wikipedia , lookup
Ingres (database) wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Relational algebra wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Microsoft Access wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Clusterpoint wikipedia , lookup
Versant Object Database wikipedia , lookup
Transcript
DB Implementation: MS Access Queries MS Access Queries Database Queries Core DBA skill From SQL to Query by Example (QBE) What does it do? Find target information • Retrieve, Filter, Sort, Aggregate/Summarize Manipulate data • Perform calculations • Add, Change, Delete, Combine data in tables • Assemble/Supply data for forms and reports How does it work? Access translates QBE to SQL SQL performs data manipulations based on Relational Algebra Access queries create a dynaset (“live” view of table) • changes made in data by query is reflected in underlying tables Database Design 2 Access Queries: Views Datasheet view For displaying the result of the query Useful for reviewing/validating the query Design View For creating/modifying a query using drag & drop GUI (i.e., QBE) Consists of Diagram Pane & Grid Pane • Add tables/queries to the Diagram Pane • Add fields to the Grid Pane (Field row) Can sort/filter/compute by fields • Sort row: set to Ascending/Descending • Criteria row: use Expression to apply data filter • Total row: compute (sum, min, max, count, etc.) of each field Automatically generates SQL statements SQL View For creating/modifying a query by manually writing SQL statements Only way to create SQL-specific queries • Union/Data-definition/Pass-through query Database Design 3 Access Queries: Basic Types Simple Query Uses one table/query To generate a subset (row/column) of a table Multi-table Query Joins multiple tables/queries To merge small chunks of data in normalized tables • Linked tables are automatically linked in in the Query Design Grid • Creating a link in the Query Design Grid does not permanently link tables Select Query Selects records that meet given criteria Does not change the data Parameter Query Prompts for query criteria values (parameters) to run a dynamic query Database Design 4 Access Queries: Sort & Filter Datasheet View Sorting • Click column and right-click Filtering • Filter Tool (Home tab) – Filter by Selection – Filter by Form – Advanced Filter/Sort Design View Sort using the Sort Row • Sort priority is from left to right for multiple sort Filter using the Criteria Row • Criteria in multiple rows make OR query • Criteria in single row make AND query • Criteria in a single cell – AND/OR – Wildcards (*) in Like and Between » e.g. Like “A*”, Like “[A-C]*”, Like “*av*”, Like “ave?”, Not Like “A*” » e.g. Between 1950 and 1960, >1960 Database Design 5 Access Queries: Query Criteria Query Criteria Expressions Expression Returns Between #1/1/99# and #12/31/99# Dates from 1/1/99 to 12/31/99 In (“John”,”Mary”,”James”) Records with John, Mary, or James Is Null Records with no entry Like “Acc?ss” ‘Acc’ followed by any character, followed by ‘ss’ Like “*s” Ends in ‘s’ Like “v*” Starts with ‘v’ <1000 Less than 1000 1000 Equal to 1000 Like “[A-C]??” Starts with A through C and has two more characters ???? Any four characters Len([Surname])= Val(4) Any Surname of 4 characters Right([Surname],2)= “ss” Any Surname ending in “ss” Left([Surname],2)= “ac” Any Surname starting with “ac” Database Design 6 Access Queries: Expressions Using expressions to create a calculated column Enter expressions in blank column of query design view • NAME: [Field1] operator [Field2] Format the display in Format property of the field Examples Simple math • DiscountPrice: [Discount] * [StandardPrice] String Concatenation • Name: [FirstName] & “ ” & [Lastname] Date & Time math • DateDiff(Interval, BeginDate, EndDate) – HireAge: DateDiff(“yyyy”,[BirthDate],[HireDate]) • DateAdd(Interval, Number, Date) – RetireDate: DateAdd(“yyyy”,25,[HireDate]) Customized Sorting • Switch(expr1, value1, expr2, value2, etc.) – Switch([City]=“Seatle”, 1, [City]=“Redmond”, 2, etc.) Database Design 7 Access Queries: Dynamic Criteria Parameterized Queries Dynamic query based on varying criteria value • e.g. retrieve books written by a given author Enter the parameter name in square brackets in criteria • • Do not use existing field names Can use expressions – e.g. Like "*" & [Last Name] & "*“ Query Criteria from Form Entries Use a form to enter query parameter values • good for multiple parameter entries 1. 2. 3. Create a parameter query Create a form with unbound input control for each of query parameters Add a command button that will run the parameter query • 4. Database Design Run Query Action of Miscellaneous Category Reference the form controls that hold parameter values from the query • i.e. change the criteria to form controls • Parameter name = fully qualified name of form control 8 Access Queries: Joins Inner Join Default join in Access (i.e. Natural Join) Returns only the records where joined fields are equal in both tables Left Outer join Returns all records from the left table Right Outer join Returns all records from the right table Database Design 9