how to add unique key in mysql

If you need to add a unique key from mysql table. How can you add that using mysql query? There are two methods to add index in mysql.  One is MySql Query and another is GUI.  First Method to add using MySql Query: To add a unique key use : alter table your_table add UNIQUE(target_column_name); To add multiple column for a unique key use: ALTER TABLE ADD UNIQUE( column_name1, column_name2, column_name3); 

In this method you have to open GUI interface of MYSQL and then go to that database and then go to that particular table in which you want to add index.First you need to select one column or you can select multiple columns as required and then click on index option (here unique). That's all.

If you need to add a unique key from mysql table. How can you add that using mysql query?

There are two methods to add index in mysql.  One is MySql Query and another is GUI.


First Method to add using MySql Query:

To add a unique key use :

alter table your_table add UNIQUE(target_column_name);


To add multiple column for a unique key use:

ALTER TABLE ADD UNIQUE( column_name1, column_name2, column_name3);


To know the name of the index you want to delete or update

SHOW INDEX FROM


To delete an index

ALTER TABLE DROP INDEX ;


Second Method to add using MySql GUI (phpMyAdmin):


In this method you have to open GUI interface of MYSQL and then go to that database and then go to that particular table in which you want to add index.

After that click on the structure option, Then you can see table structure and below you can see table columns. First you need to select one column or you can select multiple columns as required and then click on index option (here unique). That's all.



Related Blogs

pwd-system-asenwebmedia

How to remove sAntivirus | Segurazo Virus?

I have made this video "How to remove sAntivirus" only because I have troubled with this unwanted software and thought that if same type of problem arises for others then they can get help with this video as well as my blog. SAntivirus software or threat comes automatically in my laptop or it may come from other software installation from website or it may come any browser when installing extra browser plugins or browser extensions. There may be any reasons to come this virus as I was not aware of this..

pwd-system-asenwebmedia

How to backup databases in SQL server | cloud backup

To back up the database regularly is the most important part of any business or company. Not only the IT person, common employee should know the process of backup of SQL Server. This is very simple and easy to understand. I have made this video 'How to backup databases in SQL server' through Microsoft Visual Studio for those people who doesn't know how to do this. In information technology, a backup, or data backup is a copy of computer data taken and stored elsewhere so that it may be used to restore the original after a data loss event.

pwd-system-asenwebmedia

How to create a google account - what is gmail?

I have made this video "How to create a google account" for the youtube viewers and for those who does not know how to create a new google account. This is very basic introduction for the beginners. First open google chrome and search for as 'create google account' and then open the first link https://account.google.com then you will ask for your details to input like your first name, your last name, gmail id, password and confirm password and your phone number. So, input all the information correctly then click next and accept the agreement..

List of Categories

  • 5 Internet Basics
  • 14 PHP & MySql
  • 7 PHP & MSSQL SERVER
  • 2 How to trade in stock market