difference in INDEX's

Started by Brianalmost 28 years ago2 messagesgeneral
Jump to latest
#1Brian
signal@shreve.net

Is there a difference in doing:

foo int PRIMARY KEY

and

CREATE INDEX idx1 on table (foo);

does both do the same thing (create an index)? is one faster or preffered
over the other?

/-------------------------- signal@shreve.net -----------------------------\
| Brian Feeny | USR TC Hubs | ShreveNet Inc. (318)222-2638 |
| Network Administrator | Perl, Linux | Web hosting, online stores, |
| ShreveNet Inc. | USR Pilot | Dial-Up 14.4-56k, ISDN & LANs |
| 89 CRX DX w/MPFI, lots of |-=*:Quake:*=-| http://www.shreve.net/ |
| mods/Homepage coming soon |LordSignal/SN| Quake server: 208.206.76.47 |
\-------------------------- 318-222-2638 x109 -----------------------------/

#2Goran Thyni
goran@bildbasen.se
In reply to: Brian (#1)
Re: [GENERAL] difference in INDEX's

Brian wrote:

Is there a difference in doing:

foo int PRIMARY KEY

and

CREATE INDEX idx1 on table (foo);

Yes,

create table bar (foo int PRIMARY KEY);

is the same as

create table bar (foo int NOT NULL); CREATE UNIQUE INDEX bar_pkey on
table bar(foo);

The first is easier to type,
the second is preferable (faster) if you will initially do a lot of
inserts, like:

create table...
loads of inserts...
create unique index...