David542
David542

Reputation: 110203

Different in index vs constraint syntax

I'm a bit unclear on the terminology when creating an index or constraint. For example:

When is FOR used and when is ON used? Or are they two different versions, or is one deprecated? I've also seen ASSERT vs. REQUIRE used and also not sure when to use which.

Upvotes: 1

Views: 126

Answers (2)

Richard
Richard

Reputation: 135

The syntax CREATE CONTRAINT [constraint_name] ON ... ASSERT ... appears to be old. It is not referred to specifically in the current documentation (v4.4). However, it is referred to on the same page as deprecated for the DROP CONSTRAINT command.

The current syntax is consistently CREATE CONTRAINT [constraint_name] FOR ... REQUIRE ...

Upvotes: 3

Graphileon
Graphileon

Reputation: 5385

If you use CREATE INDEX, it does not enforce unicity. So basically to speed up searches. CREATE CONSTRAINT does enforce unicity.

When you do :schema, you will see that in both cases, an index is created, because also to enforce unicity, quick lookup helps al lot :)

Upvotes: 0

Related Questions