문제

I want to create an index using this query:

CREATE  INDEX `PRIMARY` ON `elements` (`id`) USING BTREE

Or something like that, I've tried several queries:

1. CREATE  INDEX `PRIMARY` ON `elements` (`id`) USING BTREE
2. CREATE  INDEX 'PRIMARY' ON `elements` (`id`) USING BTREE
3. CREATE  INDEX `PRIMARY` ON 'elements' (`id`) USING BTREE
4. CREATE  INDEX PRIMARY ON elements (`id`) USING BTREE
5. CREATE  INDEX PRIMARY ON elements (id) USING BTREE

I've also tried the 5 queries above without "USING BTREE". But I'm always getting this message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PRIMARY ON 'elements' (`id`) USING BTREE' at line 1

This one works:

CREATE INDEX test ON elements (brandid); 

I can't really discover a big difference between the two. Why can't I create an index with name PRIMARY?

도움이 되었습니까?

해결책

PhpMyAdmin creates PRIMARY KEY (which is actually unique index) using syntax like this:

ALTER TABLE `elements` ADD PRIMARY KEY(id)

You can have only one PRIMARY KEY per table.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top