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.
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:
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.
WHERE code = 2
In the example, only the registration of the product table that has the code 2 will appear.
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]);
INSERT INTO product (code,name) VALUES (1,’television’);
The record update command in MySQL is the UPDATE. Its structure is shown below:
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.
SET name = ‘TV’;
WHERE code = 1
In the example above, only the record with code 1 will have its value changed.
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]
DELETE FROM product WHERE code = 1
Check out more content on our blog!
Learn all about Scriptcase.
You might also like…