GniruT
GniruT

Reputation: 731

How to index phone numbers?

I have the following table:

CREATE TABLE persons
(
  did integer NOT NULL,
  name character varying(20) NOT NULL,
  mobil character varying(20),
)

And I want to use an index for mobil, the mobile number of a person. How could I do it? Would be that as simple as this?

create index mobil_persons on persons(mobil);

I'm not sure because I can remember that this kind of index doesn't work well on string-types.
Can anyone help me?

Upvotes: 2

Views: 1185

Answers (2)

user1206862
user1206862

Reputation:

Yes, that would be as simple as this:

CREATE UNIQUE INDEX mobil_persons ON persons(mobil);

I would use the UNIQUE keyword though, to enforce uniqueness over the "mobil" column of the "persons" table. This way, you require the database to check for duplicate column values in the table, every time data is added in the table. Any attempt to add duplicate entries will produce an error.

Upvotes: 1

Mureinik
Mureinik

Reputation: 311438

To make a long story short - yes, it's as simple as that. That's the right syntax, and it should work just fine with character data.

Upvotes: 1

Related Questions