sql query in ms access. Introduction. Sql - language for accessing and managing databases access Examples of sql queries in access

SQL is one of the most common programming languages ​​for creating and managing a database, as well as for carrying out various actions with the data itself.

As practice shows, it is quite easy to learn and makes maximum use of standard vocabulary in English. Like any other programming language, SQL has its own logic and syntax, a set of main commands and rules for their use.

Classification of SQL commands

All standard ones can be considered based on their purpose. The following sets can be taken as the basis for informal classification:

    Commands for building queries.

    Commands of built-in procedures and functions.

    Commands for triggers and system tables.

    Sets of combinations for working with date and string variables.

    Commands for working with data and tables.

This classification can be continued indefinitely, but the main sets of SQL commands will be built precisely on the basis of these types.

Considering the classification of language, one cannot fail to mention that it is universal, as evidenced by the scope of its use. This programming language and its variants are used not only in the standard environment, but also in other programs that, one way or another, you have used.

The scope of use of SQL can be considered from the point of view of office software, namely MicrosoftAccess. This language, or rather its version - MySQL, allows you to administer databases in Internet networks. Even the Oracle development environment uses SQL commands at the heart of its queries.

Using SQL in MicrosoftAccess

One of the most simple examples The language used for database programming is considered to be the Microsoft Office software package. Studying this software product is provided for in the school computer science course, and in the eleventh grade the MicrosoftAccess database management system is discussed.

It is by learning this application that students become familiar with the database development language and gain a basic understanding of everything involved. Access SQL commands are quite primitive, of course, if you consider them at a professional level. Executing such commands is very simple, and they are created in a custom code editor.

Let's look at a specific example:

SELECT Pe_SurName

WHERE Pe_Name = "Mary";

Based on the syntax of the command, you can understand that it will return to the user the last name of a person, in this case a woman named Mary, which is stored in the Contacts database table.

Though using SQL Access is limited, sometimes such simple queries can greatly simplify the task at hand.

Using SQL Commands in Oracle

Oracle is probably the only serious competitor to Microsoft SQL Server. It is this development and management environment that constantly leads to the improvement of the functions of Microsoft's software product, since competition is the engine of progress. Despite constant competition, Oracle's SQL teams replicate SQL. It is worth noting that although Oracle is considered an almost complete copy of SQL, the logic of this system and the language as a whole is considered simpler.

The Oracle system, when using a certain set of commands, does not have such a complex structure. Considering the capabilities of these database development environments, Oracle does not have a complex nested query structure.

This difference allows you to speed up work with data many times over, but, on the contrary, leads to irrational use of memory, in some individual cases. Oracle's structure is mainly built on temporary tables and their use. As an example: SQL commands in this system are constructed by analogy with the standards of the SQL language itself, although they differ slightly from it.

SELECTCONCAT(CONCAT(CONCAT('Employee', sname), CONCAT(SUBSTR(fname, 0, 1), SUBSTR(otch, 0, 1)), CONCAT('accepted', acceptdate)) FROM employees WHERE acceptdate > to_date ('01.01.80′,'dd.mm.yyyy');

This query will return data about employees who were hired in a certain period of time. Although the query structure is different, the execution of SQL commands in these systems is similar, except for minor details.

Using SQL on the Internet

With the advent of the World Wide Web, that is, the Internet, the scope of use of the SQL language is expanding. As you know, a lot of information is stored on the network, but it is not randomly located, but placed on sites and servers according to certain criteria.

Databases are directly responsible for storing information on the Internet, as in other places, and websites are management systems. As a rule, websites and their program code are organized into different languages programming, but databases are based on one of the varieties of SQL, namely the database creation language, oriented towards MySQL web interfaces.

The syntax and basic set of commands of this language completely copy the familiar SQL, but with some of its own additions, which make it different from Microsoft tSQL Server.

SQL commands are completely similar not only in syntax, but also in the standard set of function words. The only difference is in the calling and structuring of the request. For example, you can consider a request to create a new table; this is the first thing children are taught in computer science schools:

$link = mysqli_connect("localhost", "root", "", "tester");

if (!$link) die("Error");

$query = "create table users(

login VARCHAR(20),

password VARCHAR(20)

if (mysqli_query($link, $query)) echo "The table has been created.";

elseecho "Table not created: ".mysqli_error();

mysqli_close($link);

As a result of executing such a query, you can get a new “Users” table, which will have two fields: login and password.

The syntax has been changed for the Web, but is based on MicrosoftSQLServer commands.

Building MicrosoftSQLServer Queries

Selecting from tables of a specific data set is one of the main tasks of SQL. The select command in SQL is provided for such operations. This is what will be discussed below.

The rules for constructing a command are very simple, and the select command itself in SQL is constructed as follows. For example, there is a table that contains data about an employee, which, for example, has the name Person. Let's set the task that from the table you need to select data about employees whose date of birth is in the interval from the first of January to the first of March of the current year, inclusive. For such a selection, you need to execute an SQL command, which will contain not only the standard construction, but also the selection condition:

Select * from Person

Where P_BerthDay >= ‘01/01/2016’ and P_BerthDay<= ‘03/01/2016’

Executing such a command will return all data about employees whose birthday is in the period that you specified. Sometimes the task may be to display only the last name, first name and patronymic of an employee. To do this, you need to construct the request a little differently, for example, this way:

SelectP_Name - name

P_SurName - surname

P_Patronimic - patronymic

Where P_BerthDay >= ‘01/01/2016’ and P_BerthDay<= ‘03/01/2016’

However, this is just a choice of something. It, in essence, does not affect anything, but only provides information. But if you decide to take the SQL language seriously, you will have to learn how to make changes to databases, since building them without this is simply impossible. How this is done will be discussed below.

Basic SQL Commands for Changing Data

The language syntax is built not only for executing queries, but also for manipulating data. The main task of a database programmer is to write scripts for selections and reports, but sometimes it is necessary to make changes to tables. The list of SQL commands for such actions is small and consists of three main commands:

    Insert (trans. Insert).

    Update (trans. Update).

    Delete (trans. Delete).

The purpose of these commands is easy to determine; all you need to do is translate their name. These commands are easy to use and have a simple structure, but it is worth mentioning that some of them, if used incorrectly, can cause irreparable harm to the database.

As a rule, before using such MSSQL commands you need to think through it and take into account all the possible consequences of their execution.

Having learned these commands, you can fully start working with database tables, thereby modifying it and introducing some new variables or deleting old ones.

Insert command

To insert data into a table, the safest command is Insert. Incorrectly inserted data can always be deleted and re-entered into the database.

The Insert command is intended for inserting new data into a table and allows you to add both a complete set and selectively.

For example, consider the insert command into the previously described Person table. In order to enter data into a table, you need to run an SQL command that will allow you to insert all the data into the table or fill it selectively.

Insert into person

Select ‘Grigoriev’,’Vitaly’,’Petrovich’,’01/01/1988’

Commands of this type automatically fill all table cells with the specified data. There are situations when an employee does not have a middle name, say, he came to work from Germany as an exchange student. In this case, you need to execute a data insertion command, which will enter into the table only what is needed. The syntax of such a command will be as follows:

Insertintoperson(P_Name, P_SurName ,P_BerthDay)

Values ​​('David', 'Hook', '02/11/1986')

Such a command will fill only the specified cells, and all others will have the value null.

Command to change data

To change the data of both the entire row and some cells, use the Update SQL command. You need to execute such a command only with a certain condition, namely, indicate exactly which line by number you need to make changes to.

The Update SQL command has a simple syntax. For correct use, you must indicate which data should be changed in which column and in which record. Next, create a script and execute it. Let's look at an example. We need to change the date of birth of David Hooke, who is listed as number 5 in the employee table.

Set P_BerthDay = '02/10/1986' where P_ID = 5

The condition (in this script) will not allow you to change the date of birth in all table records, but will update only the necessary ones.

It is this command that programmers use most often, since it allows you to change the data in the table without causing significant damage to all the information.

Commands for using built-in procedures and functions

Using the SQL language, you can not only build queries, but also create built-in mechanisms for working with data. As a rule, there are times when you need to use a selection that was written earlier in the body of one request.

If you judge logically, then you need to copy the text of the selection and paste it into the right place, but you can get by with a simpler solution. Let's consider an example when a button for printing a report, say in Excel, is displayed on the working interface. This operation will be performed as needed. Built-in stored procedures are used for such purposes. The commands in this case are enclosed in a procedure and called using the SQLExec command.

Let's assume that a procedure has been created to display the date of birth of employees from the previously described Person table. In this case, there is no need to write the entire request. To obtain the necessary information, simply execute the Exec [procedure name] command and pass the parameters necessary for sampling. As an example, we can consider the mechanism for creating a procedure of this nature:

CREATEPROCEDUREPrintPerson

@DB smalldatetime

@DE smalldatetime

SELECT * from Person

FROM HumanResources.vEmployeeDepartmentHistory

WHERE P_BerthDay >= @DB and P_BerthDay<= @DE

ANDEndDateISNULL;

This procedure will return all information about employees whose birthday will be in a given time period.

Organization of data integrity. Triggers

Some MS SQL commands, one might even say constructs, allow you not only to organize manipulations with data, but also to ensure their integrity. For such purposes, the language contains system constructs that are created by the programmer himself. These are so-called triggers that can provide data control.

In this case, standard SQL query commands are used to organize the checking of conditions. In triggers, you can create a lot of conditions and restrictions for working with data, which will help control not only access to information, but also prohibit deleting, changing or inserting data.

There are no restrictions on the types of SQL commands that can be used in a trigger. Let's look at an example.

If we describe the mechanism for creating a trigger, the types of SQL commands here are the same as when creating a procedure. The algorithm itself will be described below.

First of all, we need to describe the service command for creating triggers:

We indicate for which data operation (in our case it is a data modification operation).

The next step is to specify the tables and variables:

declare @ID int. @Date smalldatetime @nID int. @nDatesmalldatetime

DEclare cursor C1 for select P_ID, P_BerthDay from Inserted

DEclare cursor C2 for select P_ID, P_BerthDay from deleted

We set the data selection steps. Afterwards, in the body of the cursors we write the condition and the reaction to it:

if @ID = @nID and @nDate = "01/01/2016"

sMasseges "The operation cannot be performed. The date is not suitable"

It is worth mentioning that a trigger can not only be created, but also disabled temporarily. This manipulation can only be carried out by a programmer by executing the SQL SERVER commands:

altertablePERSONdisabletriggerall - to disable all triggers created for this table, and, accordingly, altertablePERSONenabletriggerall - to enable them.

These basic SQL commands are the most commonly used, but their combinations can be varied. SQL is a very flexible programming language and gives the developer maximum possibilities.

Conclusion

From all of the above, we can draw the only conclusion: knowledge of the SQL language is simply necessary for those who are going to seriously engage in programming. It underlies all operations performed both on the Internet and in home databases. That is why a future programmer must know many commands of this language, since only with their help can one, so to speak, communicate with a computer.

Of course, there are disadvantages, as in everything in this world, but they are so insignificant that they simply pale in comparison with the advantages. Among all programming languages, SQL is practically the only one of its kind, because it is universal, and knowledge of writing scripts and codes underlies almost all sites.

The main advantage of SQL can undoubtedly be considered its simplicity, because, after all, it is included in the school curriculum. Even a novice programmer who doesn’t really understand languages ​​can handle it.

Creating a Power Design Table Using DDL

All database definition steps that can be done using a RAD tool such as Access can also be done using SQL. In this case, instead of clicking menu items, you enter commands using the keyboard. Those who prefer to manipulate graphical objects find RAD tools easy and natural to understand and learn. Others, who prefer to put words into sentences that have a certain logic, believe that SQL commands are easier and more natural. Since some things are easy to represent using the object paradigm, and others are easy to handle using SQL, it is useful to have a good knowledge of both methods.

The following sections will use SQL to perform the same table creation, modification, and drop actions that the previous section used the RAD tool to perform.

Using SQL with Microsoft Access

Access was designed as a rapid application development (RAD) tool that requires no programming. Although you can write and execute SQL commands directly in Access, you can also do this through the back door. To open the main editor, which is used to enter SQL code, follow these steps:

  1. Open the database, and then select Queries from the Objects list.
  2. In the task pane, located on the right side of the window, select the Create a query in design view option. The Add Table dialog box appears.
  3. Select any of the tables, click on the Add and Close buttons. Ignore the cursor that blinks in the newly created Query window.
  4. From the Access main menu, select View SQL Mode. An editor window appears with the starting SQL SELECT statement.
  5. Remove the SELECT statement and then enter the required SQL statement.
  6. When finished, click on the Save icon. Access prompts you to enter a name for the query you just created.
  7. Enter a name for the request and click OK.

The command you just created will be saved and executed later as a query. Unfortunately, Access does not run the full range of SQL commands. For example, it does not execute the CREATE TABLE command. However, once you create a table, you can perform almost any necessary transformation on the data in it.

Creating a table

When working with a full-featured DBMS, such as Microsoft SQL Server, Oracle 9i, or IBM DB2, you must enter the same information when creating a table using SQL as you would when creating a table using a RAD tool. The difference here is that the RAD tool helps you do this by providing you with a table creation dialog (or some similar structure) and preventing you from entering incorrect field names, types, or sizes. SQL won't give you that much attention. When working with SQL, you should know exactly what to do from the very beginning. An entire CREATE TABLE statement must be entered before SQL will even notice it, let alone tell you if there are any errors in the statement.

The following command creates a table identical to the one created earlier:

CREATE TABLE PowerSQL
ProposalNumber SMALL INT
FirstName CHAR (15),
LastName CHAR(20),
Address CHAR (30),
City CHAR(25),
StateProvince CHAR(2),
PostalCode CHAR(10),
Country CHAR (30),
Phone CHAR(14),
HowKnow CHAR (30),
Proposal CHAR(50),
BusinOrCharity CHAR(1);

As you can see, the information is essentially the same as when creating a table using RAD tools (as described earlier in this chapter). You can give preference to any method of creating tables. However, what is good about the SQL language is its versatility. The same standard syntax will work in any database management system.

Remember:
Any effort invested in learning SQL will pay off over time, because this language is not going to fade away quickly. And the effort you put into becoming an expert in the development environment will likely yield less of a return. And no matter how great the latest RAD tool is, rest assured that it will be replaced by better technology within two to three years. It would be great if during this time you can recoup the effort you put into learning this instrument! If you can, then use it. And if you can’t, then it would be wiser to stick to the old and proven remedy. Knowledge of SQL will pay dividends much longer
.

Previous articles discussed the issues. The technology for creating the structure of database tables “sql_training_st.mdb” based on SQL queries is considered. In addition, using SQL queries, the ACCESS DBMS tables "sql_training_st.mdb" were filled.

It is known that in relational databases, the SQL language is designed to manipulate data, define the structure of the database and its components, control user access to the database, and manage transactions or manage changes in the database.

The SQL language consists of four groups:

  • data manipulation language DML;
  • DDL Data Definition Language;
  • data management language DCL;
  • TCL transaction control language.

The DML group includes four main types of SQL queries:

  • INSERT - designed to add one or more records to the end of the table;
  • UPDATE - designed to change existing records in table columns or modify data in the table;
  • DELETE - designed to delete records from the table;
  • SELECT - designed to select data from tables.

The first three types of SQL queries (INSERT, UPDATE, DELETE), which relate to corrective queries to the database, were discussed on the page

In this article we will look at queries for retrieving data from Access database tables.

To retrieve information stored in an Access 2003 or 2007 database, you can use a SELECT query to select data from tables.

Let's compose the following SQL query (SQL statement) for sampling; to do this, select the SQL mode by executing the View/SQL Mode command. Enter the following SQL statement from the keyboard:

SELECT *
FROM Students;

This statement consists of two clauses "SELECT *" and "FROM Students". The first clause contains a SELECT statement and an identifier * ("identifier *" means listing all columns of the table). The second clause contains the FROM statement and the identifier "Students".

FROM - Defines the Students table, which contains the fields specified in the SELECT clause. It should be noted that a selection query always contains two statements: SELECT and FROM. Depending on the selection conditions, other operators may be present in the selection request. Figure 1 shows a screenshot of a request to retrieve data.


Rice. 1. SQL SELECT query to select data

In this example, a data sample is generated from all columns of the Students table.

Save the request with the name "Students-query1". As a result of executing the “Save” command, the object “Requests: Students-request1” will appear in the “Navigation Area”.

After saving the selection request, you must execute this request by clicking on the “Run” icon. The results of the “Run” command are shown in Fig. 2.



Rice. 2. Selecting data from all columns of the table Students

The SQL language does not have the functions of a full-fledged development language, but is focused on data access, so it is included in program development tools. In this case it is called embedded SQL. The SQL language standard is supported by modern implementations of the following programming languages: PL/1, Ada, C, COBOL, Fortran, MUMPS and Pascal.

In specialized application development systems of the client-server type, the programming environment is, in addition, usually supplemented with communication tools (establishing and disconnecting connections with database servers, detecting and processing errors occurring in the network, etc.), tools for developing user interfaces, design tools and debugging

There are two main methods for using embedded SQL: static and dynamic.

At static language use (static SQL) The program text contains calls to SQL language functions, which are rigidly included in the executable module after compilation. Changes in called functions can be at the level of individual call parameters using programming language variables.

At dynamic language use (dynamic SQL) it is assumed that calls to SQL functions are dynamically constructed and interpretation of these calls, for example, accessing data from a remote database, during program execution. The dynamic method is usually used in cases where the application does not know the type of SQL call in advance and it is built in dialogue with the user.

The main purpose of the SQL language (as well as other languages ​​for working with databases) is to prepare and execute queries. As a result of sampling data from one or more tables, a set of records can be obtained, called presentation.

Performance is essentially a table formed as a result of executing a query. We can say that it is a type of stored query. You can build multiple views using the same tables. The view itself is described by specifying the view identifier and the request that must be made to obtain it.



For the convenience of working with views, the concept of a cursor was introduced into the SQL language. Cursor is a kind of pointer used to move through sets of records when processing them.

The description and use of a cursor in SQL is as follows. In the descriptive part of the program, a variable of type cursor (CURSOR) is associated with an SQL statement (usually a SELECT statement). In the executing part of the program, the cursor is opened (OPEN<имя курсора», перемещение курсора по записям (FETCI-1 <имя курсора>...), followed by appropriate processing, and finally closing the cursor (CLOSE<имя курсора>).

In relational DBMSs, to perform operations on relations, two groups of languages ​​are used, which have as their mathematical basis theoretical query languages ​​proposed by E. Codd:

Relational algebra;

Relational calculus.

In relational algebra The operands and results of all actions are relations. Relational algebra languages ​​are procedural because the relation resulting from a query on a relational database is evaluated by executing a sequence of relational operators applied to the relations. Operators consist of operands, which are relations, and relational operations.

Codd relational algebra operations can be divided into two groups: basic set-theoretic and special relational. The first group of operations includes the classical operations of set theory: union, difference, intersection and product. The second group represents the development of ordinary set-theoretic operations towards real problems of data manipulation; it includes the operations: projection, selection, division and connection.

Calculus languages are non-procedural (descriptive or declarative) and allow queries to be expressed using a first-order predicate (function statements) that tuples or relational domains must satisfy. A database query executed using such a language contains only information about the desired result. These languages ​​are characterized by the presence of sets of rules for writing queries. In particular, SQL belongs to the languages ​​of this group.

Features of application SQL queries

An SQL query is a query created using an SQL statement. Examples of SQL queries are join queries, server queries, control queries, and subordinate queries.

A join query is a query that combines fields (columns) from one or more tables or queries into a single field or column in the result set of records. For example, six salespeople provide management with an inventory of their inventory every month. By creating a join query, you can combine these inventories into a result set of records, and then develop a create table query based on the join query.

A request to the server transmits SQL commands via ODBC to a server, for example, Microsoft SQL Server. Server queries allow you to directly work with tables on the server instead of joining them. The result of a request to the server can be loading records or changing data.

A control query creates or modifies database objects, such as Access or SQL Server tables.

A subquery consists of an SQL SELECT statement inside another select or change query. These instructions are entered in the “Field” line of the request form to define a new field or in the “Selection Condition” line to define the field selection condition. Subqueries are used to do the following:

Checking in a subquery for the existence of some results using the reserved words EXISTS or NO EXISTS;

Searches the main query for any values ​​that are equal to, greater than, or less than the values ​​returned in the subquery (using the ANY, IN, or ALL reserved words);

Creating subqueries within subqueries (nested subqueries).

The SQL language in Access can be used to develop screen forms, reports, as well as to create macros and VBA programs.

Relationship between QBE and SQL languages

In Access, there is a close relationship between the QBE and SQL languages. Query tables (forms) in the QBE language, filled out by the user, are converted into SQL expressions before immediate execution. That is, the SQL language is an internal standard for executing queries. This mechanism has the advantage of allowing the Access system to unify the preparation of queries for execution on local and remote computers. In the latter case, the SQL message is actually transmitted to the computer - the request server.

In Access, a query can be in one of three modes (states): Design, SQL, and Table. Design mode is used to develop a new query from scratch (without using Wizards or other tools) or to change the layout of an existing query. SQL mode is used to enter or view SQL statements. Table mode is used to work with query results.

SQL in Forms and Reports

The main sources of records in displays and reports are tables and queries. In the second case, the request can be a ready-made database query or one created when developing a form or report.

SQL in macros

Macro commands are part of macros that are used to automate the execution of frequently repeated actions in working with a database. A macro is one or more macro commands with arguments.

Macros are called from the database window or automatically when certain events occur. The event that triggers the macro can be, for example, the click of a button in the form area or the opening of a database window. Along with performing certain actions on database objects, macros can call other macros, Visual Basic programs, and external applications.

Of the many macro commands, two macro commands are directly related to SQL: Run SQL Query (Run SQL) and Open Query (OpenQuery)

Macro command Run SQL Query runs an Access change or control query using the appropriate SQL statement. This macro makes it possible to perform actions in a macro without first saving queries. You can also execute saved queries using the macro.

Change requests are SQL statements that implement the following functions: adding (INSERT INTO), deleting (DELETE), creating a table (SELECT...INTO) and updating (UPDATE)

Control requests are SQL statements that perform the following functions: create a table (CREATE TABLE), modify a table (ALTER TABLE), drop a table (DROP TABLE), create an index (CREATE INDEX), and drop an index (DROP INDEX)

The only and required argument of the macro command Running a SQL Query is a SQL statement. Macro argument as SQL text - instructions are entered manually in the macro input window or copied from the SQL window, which is often more convenient.

Macro command OpenRequest allows you to open a select or cross-query (in table, design, and preview modes), run a query to change or enter data.

The macro specifies three arguments: request name, mode, and data mode. The first argument specifies the name of the request to open and is required. The second argument specifies the query opening mode (Table, Design, and View). The third argument describes the mode of data entry into the request ("Add", "Change" and "Read Only")

SQL in VBA programs

VBA, like macros, is designed to automate repetitive operations on Access database objects.

In Access, there are the following ways to run VBA programs:

Including a program in the event processing procedure;

Calling a function in an expression;

Calling a Sub procedure in another procedure or in a debugging window;

Executing the macro command RunCode (RunCode) in a macro.

Functions are used in expressions that define calculated fields in forms, reports, or queries. Expressions are used to specify conditions in queries and filters, as well as in macros, VBA statements and methods, and SQL statements. A Sub procedure can include public VBA subroutines that are called from other procedures.

Let's look at running a database query using SQL statements in a Visual Basic for Applications program.

The request selects records from the database that satisfy certain conditions (selection request), or issues instructions to perform specified actions with records that satisfy certain conditions (change request).

There are the following ways to execute queries:

Calling the Execute method (to execute SQL queries for changes);

Creation and execution of a special QueryDef object;

Using an SQL statement as an argument to the OpenRecordset method;

Execute the OpenRecordset method on an existing QueryDef object;

Calling RunSQL and OpenQuery methods.

Execute method used if you need to make a change in the database that does not return records. For example, operations of inserting or deleting records.

QueryDef object represents a saved query definition in the database. It can be thought of as a compiled SQL statement.

OpenRecordset method used to open an object of type Recordset for performing subsequent operations on it.

RunSQL method executes a macro Running a SQL Query in VBA program

OpenQuery method executes the OpenQuery macro command in a VBA program. With it, you can open a query in Datasheet, Design, or View mode. This sets one of the following modes for working with data: adding, changing or reading only.

The choice of query execution option is determined by the programmer, taking into account the characteristics of the problem being solved.

An SQL query is a query created using SQL statements. SQL (Structured Query Language) is used to create queries and to update and manage relational databases such as Microsoft Access databases.

When a user creates a query in query design mode, Microsoft Access automatically generates an equivalent SQL statement. There are a number of queries that can only be done in SQL mode. It is often easier for experienced programmers to immediately write an expression in SQL than to create a query.

Type of request in the constructor:

In complex calculations, you have to make several queries sequentially to get the result. It is clear that these actions should be performed automatically without user intervention.

To do this, macros are used, consisting of several sequentially executed commands.

Calculations in queries, the ability to create and edit formulas.

For fields from the tables specified in the query schema, you can specify any calculations.

To make calculations, you need to add additional calculated fields to the request, the values ​​of which are calculated based on the values ​​of other fields in the request.

Summary queries, grouping, summary functions.

The final query is created using the mode - Summary query.

Three tables can be used, including a link table.

In this case, you can call the context menu from anywhere in the request (right mouse button) and select the “group operations” attribute.

A new Grouping line will appear in the request form.

Total functions: in the field for which we want to calculate totals, select the “Sum” function from the list to sum all the values ​​of the selected fields. The Count function will count the number of field values. information editing microsoft

A query is an appeal to the DBMS to perform any operations with data: selecting part of the data from the total volume, adding calculated fields, mass changing data, etc.

In the request you can:

  • - select information from several related tables;
  • - use complex selection conditions;
  • - the user can enter parameter values ​​himself and add calculated fields;
  • - perform final calculations.

Types of requests:

  • - sampling;
  • - creating a table;
  • - update (data change);
  • - adding records;
  • - deleting records.

Queries are used as record sources for forms and reports. In most cases, both in forms and in reports, before issuing, you need to select part of the data according to some conditions and sort the data. This is done using queries. The request can be stored separately or linked to a form or report.

Microsoft Access has several types of queries.