|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I tried to run some SQL through through http://sql.phpmix.com and got
an error I don't understand. Here's the SQL: CREATE TABLE zzz ( zzz mediumint(8) NOT NULL, PRIMARY KEY zzz (zzz) ); Here's the error: Invalid primary key "PRIMARY KEY zzz(zzz)" According to the source code, "Index name is not allowed for primary keys". If I run the code in phpMyAdmin, it works just fine. The thing I'm trying to figure out is... is doing "PRIMARY KEY zzz (zzz)" just considered bad practice? Browsers have quirks mode for badly written HTML - is "PRIMARY KEY zzz (zzz)" badly written SQL that phpMyAdmin and MySQL just interpret using a quirks mode of sorts? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Primary keys cannot be named, so your SQL should instead look like
this: CREATE TABLE zzz ( zzz mediumint(8) NOT NULL, PRIMARY KEY (zzz) ); phpMyAdmin is probably detecting the error and correcting it automatically. On Feb 11, 10:04 am, zelnaga <zeln...@gmail.com> wrote: > I tried to run some SQL through throughhttp://sql.phpmix.comand got > an error I don't understand. > > Here's the SQL: > > CREATE TABLE zzz ( > zzz mediumint(8) NOT NULL, > PRIMARY KEY zzz (zzz) > ); > > Here's the error: > > Invalid primary key "PRIMARY KEY zzz(zzz)" > > According to the source code, "Index name is not allowed for primary > keys". > > If I run the code in phpMyAdmin, it works just fine. The thing I'm > trying to figure out is... is doing "PRIMARY KEY zzz (zzz)" just > considered bad practice? Browsers have quirks mode for badly written > HTML - is "PRIMARY KEY zzz (zzz)" badly written SQL that phpMyAdmin > and MySQL just interpret using a quirks mode of sorts? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
(Sorry, I mistyped. I intended to corroborate what you'd already
discovered from the manual, that primary key _indexes_ cannot be named; of course the primary key field itself must have a name! Just not the index. Its name is probably displayed as "PRIMARY" when you look at the indexes list in phpMyAdmin.) On Feb 11, 10:13 am, jdbartlett <cont...@jdbartlett.com> wrote: > Primary keys cannot be named, so your SQL should instead look like > this: > > CREATE TABLE zzz ( > zzz mediumint(8) NOT NULL, > PRIMARY KEY (zzz) > ); > > phpMyAdmin is probably detecting the error and correcting it > automatically. > > On Feb 11, 10:04 am, zelnaga <zeln...@gmail.com> wrote: > > > I tried to run some SQL through throughhttp://sql.phpmix.comandgot > > an error I don't understand. > > > Here's the SQL: > > > CREATE TABLE zzz ( > > zzz mediumint(8) NOT NULL, > > PRIMARY KEY zzz (zzz) > > ); > > > Here's the error: > > > Invalid primary key "PRIMARY KEY zzz(zzz)" > > > According to the source code, "Index name is not allowed for primary > > keys". > > > If I run the code in phpMyAdmin, it works just fine. The thing I'm > > trying to figure out is... is doing "PRIMARY KEY zzz (zzz)" just > > considered bad practice? Browsers have quirks mode for badly written > > HTML - is "PRIMARY KEY zzz (zzz)" badly written SQL that phpMyAdmin > > and MySQL just interpret using a quirks mode of sorts? |
|
![]() |
| Outils de la discussion | |
|
|