PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Invalid primary key?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Invalid primary key?

Réponse
 
LinkBack Outils de la discussion
Vieux 11/02/2008, 17h04   #1
zelnaga
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Invalid primary key?

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?
  Réponse avec citation
Vieux 11/02/2008, 17h13   #2
jdbartlett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Invalid primary key?

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?

  Réponse avec citation
Vieux 11/02/2008, 17h17   #3
jdbartlett
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Invalid primary key?

(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?


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08859 seconds with 11 queries