0

5 MySql useful queries

Here I am not going to indicate most regular query like INSERT, UPDATE, DELETE and so on. I’ll demonstrate to you some other one stage up query which I feel we required these amid advancement, Generally we make basic function and classes on the double and we utilizes these capacities and classes commonly according to require. In any case, now and again you have to run mysql query powerfully in database, So these are the some mysql queries which required regularly.

1. Insert and Update query

This query is very useful to prevent from duplicate entry.
If you specify ON DUPLICATE KEY UPDATE, and a row is inserted that would cause a duplicate value in a UNIQUE index or PRIMARY KEY, MySQL performs an UPDATE of the old row. For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have similar effect:

2. Create and Drop Constraints

Often times you need to add/edit/delete constraints applied on a table. You can do so using the following queries:
Add a primary key:

Drop a Primary key:

Drop a Unique key:

3. Order By, Having Clauses

Order by is used to arrange data by a specific column and then having is used to filter that result set. These are really useful when you need some specific information from a large database.

4. Alter and Update Columns of a Table

We often change property of the table column so with the help of these query you can easily add/edit/delete existing table column property.
Add a column

Edit a column

Rename a column

Drop a column

5. Creating Dump/backup of Your Database

You can set below query on cronjob to backup you database automatically. just use below useful query and it’ll take backup of your mysql database regular bases.

Leave a Reply

Your email address will not be published. Required fields are marked *