MySQL Auto_increment - MySQL - Phptpoint.com

MySQL auto increment

/ins>

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_id Name Email Mobile
1 devesh devesh@gmail.com 9910099100
2 deepak deepak@gmail.com 9210053520
3 ravi ravi@gmail.com 9810098100
5 nitin nitin@gmail.com 9015501234

Query rearrange the auto_increment value

Output :

Emp_id Name Email Mobile
1 devesh devesh@gmail.com 9910099100
2 deepak deepak@gmail.com 9210053520
3 ravi ravi@gmail.com 9810098100
4 nitin nitin@gmail.com 9015501234

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_id Name Email Mobile
1 devesh devesh@gmail.com 9910099100
2 deepak deepak@gmail.com 9210053520
3 ravi ravi@gmail.com 9810098100
4 nitin nitin@gmail.com 9015501234

Output :

Emp_id Name Email Mobile
1000 devesh devesh@gmail.com 9910099100
1001 deepak deepak@gmail.com 9210053520
1002 ravi ravi@gmail.com 9810098100
1003 nitin nitin@gmail.com 9015501234

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.