SimpleGuy SimpleGuy - 1 year ago 71
SQL Question

Are the columns used for creating table index, implicitly UNIQUE?

I have created a table in MYSQL with below columns

create table Students (
id varchar(32) not null,
name varchar(200),
key1 varchar(450),
key2 varchar(255),
key3 varchar(255),
key4 varchar(255)

Now, i have created index for this table as

create index Students_key_inx on Students (key1(255));

Now, i haven't mentioned uniqueness for key1. Since, I believe index column should have unique values, so will MYSQL enforce uniqueness automatically ? Meaning, would I not be able to insert duplicate values for

Answer Source

Creating an index does not enforce uniqueness. Creating a unique index does:

create unique index unq_students_key1 on Students (key1(255));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download