Вы находитесь на странице: 1из 3

DDBMS

Distributed Database Management System (DDBMS)

Query

A query is a request for data or information from a database table or combination of tables.
A query is a question, often expressed in a formal way.

Queries are very useful tools when it comes to databases and they are often called by the user through a
form. They can be used to search for and grab (take hold of) data from one or more of your tables, perform
certain actions on the database and even carry out a variety of calculations depending on your needs.

Queries help to select information from tables. It selects columns from records, records from table/query.
You can select, summarize, update, delete, make new table, append records to table using query.

When it comes time to build a query for your database, you have two ways to go about creating it.

1. Either use the Query Wizard that Microsoft Access provides for you, or
2. Create your own queries from scratch.

Microsoft Access allows for many types of queries, some of the main ones being select, action,
parameter and aggregate queries.

Select Query

The select query is the simplest type of query and it is also the most commonly used one in Microsoft
Access databases. It can be used to select and display data from either one table or a series of them
depending on what is needed.

In the end, it is the user-determined criteria that tells the database what the selection is to be based on.
After the select query is called, it creates a "virtual table" where the data can be changed, but at no more
than one record at a time.

Action Query

When the action query is called, the database undergoes a specific action depending on what was
specified in the query itself. This can include such things as creating new tables, deleting rows from
existing ones and updating records or creating entirely new ones.

Action queries are very popular in data management because they allow for many records to be changed
at one time instead of only single records like in a select query.

Four kinds of action queries are:

1. Append Query – takes the set results of a query and "appends" (or adds) them to an existing
table.
2. Delete Query – deletes all records in an underlying table from the set results of a query.
3. Make/Create Table Query – it creates a table based on the set results of a query.
4. Update Query – allows for one or more field in your table to be updated.

1
DDBMS
Parameter Query

In Microsoft Access, a parameter query works with other types of queries to get whatever results you are
after. This is because, when using this type of query, you are able to pass a parameter to a different query,
such as an action or a select query. It can either be a value or a condition and will essentially tell the
other query specifically what you want it to do.

It is often chosen because it allows for a dialog box where the end user can enter whatever parameter
value they wish each time the query is run. The parameter query is just a modified select query.

A parameter query is one of the simplest and most useful advanced queries you can create. It allows
you to create a query that can be updated easily to reflect a new search term. When you open a parameter
query, Access will prompt you for a search term and then show you query results that reflect that search.

For example, [Enter the start date:]

Aggregate Query

A special type of query is known as an aggregate query. It can work on other queries (such as selection,
action or parameter) just like the parameter query does but instead of passing a parameter to another
query it totals up the items by selected groups.

It essentially creates a summation of any selected attribute in your table. This can be further generated
into statistical amounts such as averages and standard deviation, just to name a couple.

The SQL aggregate functions available to Microsoft Access are:

• Sum, Avg, Min, Max, First, Last, Group By, Count, Var, Expression, Where etc.

Query Language:

Query language (QL) refers to any computer programming language that requests and retrieves data from
database and information systems by sending queries. It works on user entered structured and formal
programming command-based queries to find and extract data from host databases. This is the most
complex method because it forces you to learn a specialized language, but it is also the most powerful.

They provide a means of retrieving records or parts of records and performing various calculations before
displaying the results. The interface by which such manipulations are specified is called the query
language. Whereas early query languages were originally so complex that interacting with electronic
databases could be done only by specially trained individuals, modern interfaces are more user-friendly,
allowing casual users to access database information.

Web search query: A query entered by users into web search engines.

Structured Query Language (SQL)

SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate
with a database. According to ANSI (American National Standards Institute), it is the standard language
for relational database management systems (RDBMS).

2
DDBMS
SQL Queries

CREATE TABLE student (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)

insert into student (id, name, age) values (2, 'amy', 26); // ('2', "amy", '26')
insert into student (id, name, age) values (3, 'bob', 27)
insert into student values (4, 'chris', 28)
insert into student (id, name, age) values (5, 'dan', 26)
insert into student (id, name, age) values ('6', "amy", '28')
insert into student (id, name) values (7, 'nan')

SELECT * FROM student

SELECT MAX(age) FROM student


SELECT MIN(age) FROM student
SELECT sum(age) FROM student

SELECT name FROM student WHERE age > 25


SELECT name, age FROM student
SELECT age, name FROM student

DELETE FROM student WHERE age = 26

ALTER TABLE student ADD DateOfBirth date


ALTER TABLE student DROP COLUMN DateOfBirth

Вам также может понравиться