Common commands in databases

 

Within the routine of those who work with databases, some commands are indispensable for the activities to be carried out. Commands of query, insert, update and registration of exclusion are some of them and we will explain how each of them works in MySQL as following.

SELECT MYSQL

The SELECT command is used to return all the records of a particular table in the form of consultation. The syntax used in MySQL is:

SELECT [Fields]

FROM [Table]

Exemple:

SELECT *

FROM products

The command allows that all or certain columns are displayed. For that, you just need to indicate the name of each column or use the character (*), as shown in the previous example. It can still have a WHERE conditional, used in filters. With it, the only the record that meets the conditional will be displayed.

SELECT *

FROM products

WHERE code = 2

In the example, only the registration of the product table that has the code 2 will appear.

INSERT MYSQL

Inserting a record in MySQL is through the INSERT command. Tables, columns, and also the values that are stored on it are indicated.

INSERT INTO [Table] ([Columns]) VALUES ([Values]);

Exemple:

INSERT INTO product (code,name) VALUES (1,’television’);

 

UPDATE MYSQL

The record update command in MySQL is the UPDATE. Its structure is shown below:

UPDATE [Table]

SET [Column] = [Value]

This more generic framework can be used to update all of the table at once, but this is totally inadvisable. Ideally, when you update a record in a table is that the WHERE conditional is present, thus avoiding possible failures.

UPDATE product

SET name = ‘TV’;

WHERE code = 1

In the example above, only the record with code 1 will have its value changed.

DELETE MYSQL

Just as the UPDATE command, the DELETE one will need to be used very carefully. This is because, when updating or deleting a database record, it may not be redeemed – only with restoring a backup that will be possible. The command syntax is very simple and should also be used with a conditional, as shown in the following example:

DELETE FROM [table] WHERE [conditional]

Exemple:       

DELETE FROM product WHERE code = 1

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.