Reputation: 731
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
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
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