Open Source Tutorials - Open Source Training
Open source training & tutorials from experienced, passionate people
chrome icon firefox icon ie icon opera icon safari icon Sings in these Browsers
A- A A+

By A Web Design

pdf icons

Creating A MySQL Composite-Unique Index

The columns included in a composite index can hold duplicate values. To create an index that will not hold duplicate values, an index can be: Composite Unique Index

Composite Unique index:

A unique index created on multiple table columns is called a Composite Unique index.
The following is the syntax for creating a Composite Unique index as shown in Diagram 1.

Syntax:
<System prompt> CREATE UNIQUE INDEX <IndexName> ON <Table Name> (<Column Name>, <Column Name>);

Example:
mysql> CREATE UNIQUE INDEX product _id ON productdetail (Serial_NO, ID);

diagram1.gif
Diagram 1

Testing whether the index was created:

To test whether the unique index has been bound to the productdetail table, execute the SHOW CREATE TABLE statement as shown in Diagram 2:

The following is the syntax for verifying the index created on a column(s) of a table
Syntax:
<System prompt> SHOW CREATE TABLE <Table Name> \G;

Example:
mysql> SHOW CREATE TABLE productdetail \G;

diagram2.gif
Diagram 2

In Diagram 2, UNIQUE KEY ‘product_id’ (‘Serial_NO,ID’) indicates that the unique index is successfully created on the column ‘Serial_NO’ and ‘ID’.

OSV Newsletter


Receive HTML?

NOTE: To prevent subscription to the OSV newsletter, uncheck the checkbox above.
Guest Blog for OSV
Free Ebook Download
LinkShare_180x150
Artisteer - DNN Skin Generator
Tapestry Theme - A Tumblog-Style Theme for Wordpress