What is a Query ? This is the Definition, Function, How it Works and Examples

What is a Query ? This is the Definition, Function, How it Works and Examples

Technatic | Have you ever heard the term query ? This term refers to a command for database management, including websites and social media that you frequently use. Maybe you are wondering how social media can store user personal data. Then, how can you comment and send messages between users ? Or how can you upload photos and delete them from social media.

What is a Query ?

The definition of a query is a command directed at the database to perform certain tasks. In other words, a query is a request to the database to manage data according to orders. Usually, the commands used are in the form of code called a query language.

Read Also : Document Type Definition (DTD): Meaning, Syntax and 3 Main Benefits

In fact, there are quite a lot of languages that are often used, such as Datalog, Data Mining Extensions (DMX) or Ariel Query Language (AQL). However, in the majority of database applications, the query language that is often used is Structured Query Language (SQL). This language is the easiest to understand by the database system, so it can facilitate communication between requests and commands.

Query Function

The main function of a query is as a database processing command on a website or application. In processing this data, it is used to carry out the following commands.

  • As a command to manipulate existing data
  • Enter new data and delete other data
  • Determine the data structure in table form
  • Add, delete, and also retrieve commands on the database
  • Perform direct access to the database

How Queries Work

Basically, the way this command works is almost the same as communication between humans. Have you ever asked a friend to pick up an item? Well, the request is a code. Your friend will carry out commands as requested, provided they both speak and understand the same language. The way it works is by translating the meaning of the command code, so that the system can understand it and execute it as requested.

It should be noted that the language used by the user and the database must be the same in order to communicate well. Usually, databases are stored in the form of tables consisting of several columns containing information. Query is a command that can influence data processing activities. For example, the select command can provide an action on the database to select data, or the action command can provide an action to add, delete, or change that data.

Types of Query

This command has three main types in SQL. Basically, these three types have the same task, namely to manage data objects. The following is an explanation of each type.

1. Data Definition Language (DDL)

DDL is a command used to define data in a database, such as creating and changing tables, creating indexes, forming certain table structures, and so on.

Some commands included in this type are as follows.

  • Create: Function to create a database table
  • Drop: Function to delete database tables
  • Truncate: Function to delete data from a table without changing its structure
  • Alter: Function to change the table structure. Such as adding and deleting columns

2. Data Control Language (DCL)

As the name suggests, DCL query means a command that is tasked with providing control over the database, such as allowing or denying access, auditing usage, and also allocation.

The following are some commands that are included in the DCL type.

  • Commit: Function to save and assign the database
  • Rollback: Function to cancel database changes
  • Grant: Functions to grant access to users
  • Revoke: Function to deny and revoke access to users

3. Data Manipulation Language (DML)

DML query is a type of command that functions to manipulate data. In this type, you can change or add information contained in the database table.

The following are some commands that are included in the DML type.

  • Update: Used to modify information in the table
  • Insert: Used to create a new table addition command
  • Delete: Function to delete data in a table
  • Lock: Functions to lock tables as access control
  • Call: Function to execute a saved command

Example Query

Some examples of query usage are as follows.

1. Create a Database

A database is a base used to store data in relatively large sizes. Before inputting information data, you must first create a database as a place to store it. You can create this database by using the 'create' query, which is the command to create a database.

A database is a base used to store data in relatively large sizes. Before inputting information data, you must first create a database as a place to store it. You can create this database by using the 'create' query, which is the command to create a database.

Read Also : Get to Know the 3 Differences Between Databases and Data Warehouses

For example, when you want to create a database for employee personal data in a company, what is written in the query is 'create company database. If the database is created successfully, it will display an OK code.

Next, if you want to see the existing database, you can write 'show database', then this command will display all existing databases on the server.

2. Create a table

Tables are also something that must be present in a database. Because, all data information will be stored in table form. So, before you enter data into the database, you must first create a table. To create a table, you must activate the database first. This is because tables can only be inserted into an active database.

In the previous example, the way to activate the database is with the 'use Company' command. After that, you can add a table with the command 'create table table_name'. This means, if you want to create a table called 'Self Data', then the command written in the query is 'create table Self_Data'.

3. Input and Delete Data

After you have a database and create tables, then you can enter data in it. To enter data, the command formula written is 'insert into table_name values('column name 1', 'column name 2', 'column name 3')'.

For example, in the example table that was created previously, you can insert table columns with the command 'insert into Personal_Data values('Name','Address','Date of Birth')'.

Read Also : What is Software ? This is The Definition, Role and Tips for Choosing it

On the other hand, to delete table data, you can also use the same format, but with the 'delete' command. An example of a command written in a query is 'delete from Self_Data'. With this command, the data will be completely deleted.

So, that's some information about queries that can answer your curiosity. With queries, it will be easier for websites to identify and process data.

Technatic

Technatic is an online information media that has a vision to enlighten and provide knowledge for future leaders who dare to become GREAT individuals with quality learning materials.

Posting Komentar

Lebih baru Lebih lama

Formulir Kontak