2

Or do I have to create index manually?

CREATE TABLE pages(
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  stitle TEXT UNIQUE,
  parent INTEGER,
  FOREIGN KEY(parent) REFERENCES pages(id) ON DELETE CASCADE
);

So I should have 2 indexes, right? id and stitle

1
  • I would hope so, otherwise it might take longer to verify uniquness. Commented Aug 6, 2013 at 15:14

1 Answer 1

4

Creating a UNIQUE constraint automatically creates an index on the columns involved in the UNIQUE constraint.

Ref.

both UNIQUE and PRIMARY KEY constraints are implemented by creating an index in the database.

.... As a result, there often no advantage (but significant overhead) in creating an index on a set of columns that are already collectively subject to a UNIQUE or PRIMARY KEY constraint.

In your example, there would be 2 indexes created.

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

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.