Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do index names have to be unique across entire database in Mysql?

For example, if I have two tables Teacher and Student that would have a column named IDNumber, do I have to name the indexes separately like this:

IDNum_teach IDNum_stu  

Or could I just create an index on each table for IDNumber and name them both IDNum?

like image 940
ocean800 Avatar asked Jun 04 '15 20:06

ocean800


2 Answers

Yes you can use same index name for both the tables.

CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX IDnum [index_type] ON tbl_name (index_col_name,...) [index_type]

like image 70
Nandish Avatar answered Sep 18 '22 12:09

Nandish


Each table in an SQL database is essentially independent. So, yes, you can use the same column name IDNumber in each table.

like image 24
Kirk Powell Avatar answered Sep 19 '22 12:09

Kirk Powell