0

Please help me to create index between two tables in mysql? I have "account" and "group" table. I have to index with "group_id with index_id" and to be unique.

2
  • 2
    This question has absolutely nothing to do with PHP. Commented Jan 13, 2011 at 16:47
  • What do you mean, precisely, by "be unique" ? Commented Jan 13, 2011 at 16:47

3 Answers 3

1

MySQL table indexes are on single tables.

Perhaps you're thinking of a FOREIGN KEY, which is only available with the InnoDB storage engine.

Sign up to request clarification or add additional context in comments.

Comments

0

I just learned this myself, here, but apparently if you create a Unique constraint on a field, mySql will automatically create a nonclustered index on that field.

Comments

0

I think you're looking for a Foreign key.

This statement assumes that 'group_id' is a column in the account table and 'index_id' is a column in the group table.

ALTER TABLE account ADD CONSTRAINT group_index FOREIGN KEY (group_id) REFERENCES  group (index_id)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.