Create unique index on table columns : Index « Table Index « SQL / MySQL






Create unique index on table columns

    
mysql>
mysql> CREATE TABLE EmployeeS(
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          NAME           CHAR(15)     NOT NULL,
    ->          INITIALS       CHAR(3)      NOT NULL,
    ->          BIRTH_DATE     DATE                 ,
    ->          SEX            CHAR(1)      NOT NULL,
    ->          JOINED         SMALLINT     NOT NULL,
    ->          STREET         VARCHAR(30)  NOT NULL,
    ->          HOUSENO        CHAR(4)              ,
    ->          POSTCODE       CHAR(6)              ,
    ->          TOWN           VARCHAR(30)  NOT NULL,
    ->          PHONENO        CHAR(13)             ,
    ->          LEAGUENO       CHAR(4)              ,
    ->          PRIMARY KEY    (EmployeeNO)           );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> CREATE   UNIQUE INDEX NAMEINIT
    -> ON       EmployeeS (NAME, INITIALS);
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql>
mysql> drop table Employees;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
  








Related examples in the same category

1.Creating a Table with an Index
2.Create table: alter table to drop index
3.Create index on a column
4.Create table: Make index
5.Create index on table column with order
6.Create index on one column
7.Create index on two columns
8.Create index using btree
9.Handling Duplicate Index Values
10.Eliminating Duplicates by Adding an Index
11.How to include a unique index in the table definition.
12.How to include a regular index in a table definition:
13.Get the descriptive data of the indexes defined on the PENALTIES table.
14.Creating Indexes (CREATE INDEX)
15.Create an index on the AMOUNT column of the PENALTIES table.
16.Get the names of the indexes defined on the PENALTIES table.
17.Defining Indexes at Table-Creation Time
18.The syntax for CREATE INDEX is as follows
19.Removing Duplicates by Adding an Index
20.Removing Indexes
21.Create index of decimal type column
22.Create view for indexes
23.Drop an index by name
24.Add index to int type column
25.To create a unique-valued index, use the UNIQUE keyword instead of INDEX.
26.PRIMARY KEY INDEX_PRIM
27.Create an index and check it
28.Adding or Dropping Indexes
29.There are four types of statements for adding indexes to a table:
30.Hash index
31.Show index for a table
32.Using index in order by clause to indecate the result from subquery
33.Create a table with a nonunique index on the date-valued column Inauguration
34.To include multiple columns in an index
35.Provide index definitions in addition to the column definitions.
36.Modifying Indexes of Existing Tables
37.A table can have multiple indexes.
38.Create a single-column index on c, and the second creates a multiple-column index that includes both c and i