Delete Delete operator

Information is stored in the MySQL database in the form of tables. Each table has several columns and an arbitrary number of rows. As a rule, information is placed in rows, and its structure is determined by the names of the columns.

delete mysql

You can delete rows with a Query Delete MySQL query, but your own way of storing data is preferable. This allows you to determine the procedure for deleting information designed by the developer, and not provided for by the database query language .

Syntax and usage of Delete MySQL operator

Typically, to delete records, the developer uses simple forms of queries to the MySQL database:

  • delete from `ex_customs` - delete all records from the ex_customs table;
  • delete from `ex_customs` where` aCol` = '12 .13.14 '- deletes only those records that have the value '12 .13.14' in the column `aCol`;

In fact, the Delete MySQL operator offers many options for deleting records.

mysql delete from where

Initially, you can sort (order by) the table entries and delete those that satisfy specific conditions (where). A certain effect can be achieved by using the Limit option and deleting a specific number of records.

Removing only one record with a specific unique code can be done like this:

mysql query delete

In this example, only one entry will be deleted from the `is_cache` table with the value` owner_code` = 'CA011712011116164842'.

Securely delete information

If the table contains important data, then when deleting, you should take precautions and control the actions of the user who manages the contents of the database and its tables.

The record deletion algorithm should be constructed in such a way that the probability of accidental deletion of information is completely excluded.

There are many tasks that allow the free application of deletion conditions and the Limit option. For example, in the search results before displaying on the page, you can delete those entries that have a low rating or those whose information does not contain the required keywords.

delete mysql

However, in most cases, one should not only ensure that the dialogue with the user is followed exactly and be sure that he intends to delete it, but also provide a deletion algorithm in which all conditions are guaranteed to be fulfilled and deletion of the necessary records is impossible.

Using the delete operation in a database object

MySQL Query: delete, insert, and update queries in their usual form are not very convenient when developing information processing algorithms when you have to work with several tables in the same way at once.

You have to duplicate almost the same queries and use them in different places of the algorithm. If you need to update the code, making changes becomes a noticeable problem: you may miss some queries and an error will be generated.

It is very effective to create an object for working with a database, which includes four basic operations:

  • Addition (iLineIns, iLinesAdd);
  • change (iLineUpd);
  • removal (iLineDel);
  • selection (iLineSel).

All other operations: counting rows, tables, searching for minimum and maximum elements, searching for information in tables, columns depend on a specific task.

mysql delete from where

When creating an object, all calls to it are made in the same way, and if necessary, changes - only the database access object changes. Regarding the delete delete operation, MySQL here provides an additional security guarantee. If the deletion algorithm works, then it works the same way across all database tables.

Object Oriented Removal

The problem with MySQL queries: delete from * where & is that there is a set of tables (*) and a set of conditions (&). MySQL is an excellent, fast, reliable and compact database from a professional developer of large databases.

But in each subject area you always have to write specific queries, and these are potential errors. The process is time consuming and takes some time.

If the database tables contain objects, it is not necessary to have multiple tables. One is enough (maybe as many tables as you like), in which a variety of objects will be located. For example, each object of the used system of objects can write itself into a string of characters and recover from a string of characters.

In fact, an object in the context of a database is a sequence of characters. Delete an object is not a MySQL Delete statement, but a developer action that simply removes a character string from a specific database record.

mysql query delete

In this example, one database row can contain several objects in the oj_store field, while the body of the object can occupy not one database row, but several (numbering in the oj_line field). Each object has the name oj_name, the instance code oj_code and the owner of this instance is oj_owner.

With this decision, recording and deletion are performed at the object level, not the database rows. This translates the delete operation into a property of the object system, not using a particular query operator.

Source: https://habr.com/ru/post/K3104/


All Articles