SimpleGuy SimpleGuy - 3 days ago 8
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
key1
in
Students
?

Answer

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

create unique index unq_students_key1 on Students (key1(255));
Comments