MySQL auto_increment

auto_increment is keyword whose values are generated by system itself . every time a new record is entered in the database , the value of this field is incremented by one.
for example: consider a employee table tat contain four fields name, emp_id, email, mobile number
in this table emp_id is defined as auto_increment.
for any new user only three fields need to provide value , the fourth field is auto generated.
This field must be defined as integer.

How to rearrange the auto_increment field(Emp_id) after being deleted row 4

Emp_idNameEmailMobile
1deveshdevesh@gmail.com9910099100
2deepakdeepak@gmail.com9210053520
3raviravi@gmail.com9810098100
5nitinnitin@gmail.com9015501234

Query rearrange the auto_increment value

Output :

Emp_idNameEmailMobile
1deveshdevesh@gmail.com9910099100
2deepakdeepak@gmail.com9210053520
3raviravi@gmail.com9810098100
4nitinnitin@gmail.com9015501234

In above example suppose we deleted entry 4 from the table , then we have to rearrange the records in
the table and change the value of auto_incremented variable accordingly.

Initialize auto_increment field(Emp_id) from 1000 at the place of 1.

Emp_idNameEmailMobile
1deveshdevesh@gmail.com9910099100
2deepakdeepak@gmail.com9210053520
3raviravi@gmail.com9810098100
4nitinnitin@gmail.com9015501234

Output :

Emp_idNameEmailMobile
1000deveshdevesh@gmail.com9910099100
1001deepakdeepak@gmail.com9210053520
1002raviravi@gmail.com9810098100
1003nitinnitin@gmail.com9015501234

The value of auto_increment is 1 by default.
if we want to start the value from any different values say 1000 then we can do it with the help of
above mentioned query.

MySQL password encryption

MySQL encryption is used to encrypt the password stored in the database.
By this technique we are able to change the format of the password so that if any unauthorized person get the access to database , he will not able to access the account.
we can use some PHP function to encrypt the password.
=> mysql( )
=> md5( )
=> AES_ENCRYPT( )

MySQL password decryption

Whereas in decryption , the already encrypted password is decrypted first and used
after this operation.
=> AES_DECRYPT( )

encryption and decryption are performed at he time of storing data in database and
fetching data from it.


  • Abhishek Kashyap

    hoe to delete any table after merging it with the parent table

  • Mani

    plz for
    how to code…?
    multiple image select and store data base……