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 > value by default 0
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
value by default 0

Réponse
 
LinkBack Outils de la discussion
Vieux 19/12/2007, 13h12   #1
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut value by default 0

Hi all,


I have create a table A with a foreign key for a relation to table B.
The relation must be benot null so the corresponding attribute is set as
not null.

If I create a new A with the foreign key null, the record is saved with a 0.
I would expect that MySql would send me an exception without saving.
How can I get the correct behaviour ?

Thanks in advance for any .


Pierre

MySQl 4.0.18


  Réponse avec citation
Vieux 19/12/2007, 13h25   #2
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

On Wed, 19 Dec 2007 14:12:31 +0100, Pierre Gilquin <inconnue@bluewin.ch>
wrote:

> Hi all,
>
>
> I have create a table A with a foreign key for a relation to table B.
> The relation must be benot null so the corresponding attribute is set as
> not null.
>
> If I create a new A with the foreign key null, the record is saved with
> a 0.
> I would expect that MySql would send me an exception without saving.
> How can I get the correct behaviour ?


It does limit the insert here.
Can you show use the CREATE TABLE syntax for both tables? (and does a key
with 0 exist in B, just to be sure?)
--
Rik Wasmus
  Réponse avec citation
Vieux 19/12/2007, 13h38   #3
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

Thanks Rik,

It's something like that :

CREATE TABLE A( ID BIGINT(9) NOT NULL, linkOnTableBId BIGINT(9) NOT NULL,
.... );

ALTER TABLE interaction ADD PRIMARY KEY (ID);


This is very simple as it is generated by a Object - Relationnal Modelling
tools. The constraint for the relation is not managed in the database.
There is no attempt to create a B with id = 0.

The problem is that the default value for linkOnTableBId is 0 and I cannot
get rid of this.


Pierre






"Rik Wasmus" <luiheidsgoeroe@hotmail.com> a écrit dans le message de news:
op.t3k3ll1z5bnjuv@metallium.lan...
> On Wed, 19 Dec 2007 14:12:31 +0100, Pierre Gilquin <inconnue@bluewin.ch>
> wrote:
>
>> Hi all,
>>
>>
>> I have create a table A with a foreign key for a relation to table B.
>> The relation must be benot null so the corresponding attribute is set as
>> not null.
>>
>> If I create a new A with the foreign key null, the record is saved with
>> a 0.
>> I would expect that MySql would send me an exception without saving.
>> How can I get the correct behaviour ?

>
> It does limit the insert here.
> Can you show use the CREATE TABLE syntax for both tables? (and does a key
> with 0 exist in B, just to be sure?)
> --
> Rik Wasmus



  Réponse avec citation
Vieux 19/12/2007, 13h42   #4
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

On Wed, 19 Dec 2007 14:38:34 +0100, Pierre Gilquin <inconnue@bluewin.ch>
wrote:
> It's something like that :


'something like' is not what I'm looking for. Could you post the full
definitions? Just run SHOW CREATE TABLE <tablename>. It really saves time
to see the definitions and pinpoint it directly instead of trying to list
all possible reasons why this could/should fail.

> ALTER TABLE interaction ADD PRIMARY KEY (ID);


This is never in a CREATE TABLE syntax.
--
Rik Wasmus
  Réponse avec citation
Vieux 19/12/2007, 13h53   #5
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

This is the real one :

The main table is Interaction

SHOW CREATE TABLE interaction
CREATE TABLE `interaction` (
`audit_id` mediumint(9) default NULL,
`category` char(3) default NULL,
`ID` bigint(9) NOT NULL default '0',
`impact` char(1) default NULL,
`substance1Id` bigint(9) NOT NULL default '0',
`substance2Id` bigint(9) NOT NULL default '0',
`type` char(1) default NULL,
`pourcent` decimal(5,2) default NULL,
`Ki` decimal(15,5) default NULL,
`Km` decimal(15,5) default NULL,
`heriteAtcFromSubstance` varchar(5) default 'true',
`infoImportId` bigint(9) default NULL,
`impactValue` decimal(15,5) default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `SUB1_SUB2_IDX`
(`substance1Id`,`substance2Id`,`category`,`type`)
) TYPE=MyISAM

You can see the 2 attributes used for a relation on table Substance

( `substance1Id` bigint(9) NOT NULL default '0',
`substance2Id` bigint(9) NOT NULL default '0',)

if at least one of theses attributes is null, I would like an exception ...

CREATE TABLE `substance` (
`AUC` decimal(15,5) default NULL,
`Cmax` decimal(15,5) default NULL,
`DCI` blob,
`Q0` decimal(15,5) default NULL,
`TDemi` decimal(15,5) default NULL,
`Vd` decimal(15,5) default NULL,
`id` mediumint(9) NOT NULL default '0',
`biodisponibilite` decimal(15,5) default NULL,
`category` char(3) NOT NULL default '',
`idEMediat` mediumint(9) default NULL,
`invisible` tinyint(1) default NULL,
`isomere` char(3) default NULL,
`VERROU` tinyint(1) default NULL,
`metabolite` tinyint(1) default NULL,
`metaboliteActif` tinyint(1) default NULL,
`nomLocal` varchar(255) NOT NULL default '',
`poidsMoleculaire` decimal(15,5) default NULL,
`fu` decimal(15,5) default NULL,
`ka` decimal(15,5) default NULL,
`cl` decimal(15,5) default NULL,
`CmaxSs` decimal(15,5) default NULL,
`tauRefCmaxSs` decimal(15,5) default NULL,
`doseRefCmax` decimal(15,5) default NULL,
`tempsRefAUC` decimal(15,5) default NULL,
PRIMARY KEY (`id`),
KEY `nomSubstance` (`nomLocal`)
) TYPE=MyISAM

Pierre




"Rik Wasmus" <luiheidsgoeroe@hotmail.com> a écrit dans le message de news:
op.t3k4ca0j5bnjuv@metallium.lan...
> On Wed, 19 Dec 2007 14:38:34 +0100, Pierre Gilquin <inconnue@bluewin.ch>
> wrote:
>> It's something like that :

>
> 'something like' is not what I'm looking for. Could you post the full
> definitions? Just run SHOW CREATE TABLE <tablename>. It really saves time
> to see the definitions and pinpoint it directly instead of trying to list
> all possible reasons why this could/should fail.
>
>> ALTER TABLE interaction ADD PRIMARY KEY (ID);

>
> This is never in a CREATE TABLE syntax.
> --
> Rik Wasmus



  Réponse avec citation
Vieux 19/12/2007, 14h00   #6
Pierre Gilquin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

You are right, I tryed a more simple :

CREATE TABLE A( ID BIGINT(9) NOT NULL, linkOnTableBId BIGINT(9) NOT NULL);

ALTER TABLE A ADD PRIMARY KEY (ID);

and in this case, I cannot save with a null value for linkOnTableBId !
The problem is on the complete definition of my table

Pierre

"Rik Wasmus" <luiheidsgoeroe@hotmail.com> a écrit dans le message de news:
op.t3k4ca0j5bnjuv@metallium.lan...
> On Wed, 19 Dec 2007 14:38:34 +0100, Pierre Gilquin <inconnue@bluewin.ch>
> wrote:
>> It's something like that :

>
> 'something like' is not what I'm looking for. Could you post the full
> definitions? Just run SHOW CREATE TABLE <tablename>. It really saves time
> to see the definitions and pinpoint it directly instead of trying to list
> all possible reasons why this could/should fail.
>
>> ALTER TABLE interaction ADD PRIMARY KEY (ID);

>
> This is never in a CREATE TABLE syntax.
> --
> Rik Wasmus



  Réponse avec citation
Vieux 19/12/2007, 14h03   #7
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

On 19 Dec, 13:53, "Pierre Gilquin" <incon...@bluewin.ch> wrote:
> This is the real one :
>
> The main table is Interaction
>
> SHOW CREATE TABLE interaction
> CREATE TABLE `interaction` (
> `audit_id` mediumint(9) default NULL,
> `category` char(3) default NULL,
> `ID` bigint(9) NOT NULL default '0',
> `impact` char(1) default NULL,
> `substance1Id` bigint(9) NOT NULL default '0',
> `substance2Id` bigint(9) NOT NULL default '0',
> `type` char(1) default NULL,
> `pourcent` decimal(5,2) default NULL,
> `Ki` decimal(15,5) default NULL,
> `Km` decimal(15,5) default NULL,
> `heriteAtcFromSubstance` varchar(5) default 'true',
> `infoImportId` bigint(9) default NULL,
> `impactValue` decimal(15,5) default NULL,
> PRIMARY KEY (`ID`),
> UNIQUE KEY `SUB1_SUB2_IDX`
> (`substance1Id`,`substance2Id`,`category`,`type`)
> ) TYPE=MyISAM
>
> You can see the 2 attributes used for a relation on table Substance
>
> ( `substance1Id` bigint(9) NOT NULL default '0',
> `substance2Id` bigint(9) NOT NULL default '0',)
>
> if at least one of theses attributes is null, I would like an exception ....
>
> CREATE TABLE `substance` (
> `AUC` decimal(15,5) default NULL,
> `Cmax` decimal(15,5) default NULL,
> `DCI` blob,
> `Q0` decimal(15,5) default NULL,
> `TDemi` decimal(15,5) default NULL,
> `Vd` decimal(15,5) default NULL,
> `id` mediumint(9) NOT NULL default '0',
> `biodisponibilite` decimal(15,5) default NULL,
> `category` char(3) NOT NULL default '',
> `idEMediat` mediumint(9) default NULL,
> `invisible` tinyint(1) default NULL,
> `isomere` char(3) default NULL,
> `VERROU` tinyint(1) default NULL,
> `metabolite` tinyint(1) default NULL,
> `metaboliteActif` tinyint(1) default NULL,
> `nomLocal` varchar(255) NOT NULL default '',
> `poidsMoleculaire` decimal(15,5) default NULL,
> `fu` decimal(15,5) default NULL,
> `ka` decimal(15,5) default NULL,
> `cl` decimal(15,5) default NULL,
> `CmaxSs` decimal(15,5) default NULL,
> `tauRefCmaxSs` decimal(15,5) default NULL,
> `doseRefCmax` decimal(15,5) default NULL,
> `tempsRefAUC` decimal(15,5) default NULL,
> PRIMARY KEY (`id`),
> KEY `nomSubstance` (`nomLocal`)
> ) TYPE=MyISAM
>
> Pierre
>
> "Rik Wasmus" <luiheidsgoe...@hotmail.com> a écrit dans le message de news:
> op.t3k4ca0j5bn...@metallium.lan...
>
> > On Wed, 19 Dec 2007 14:38:34 +0100, Pierre Gilquin <incon...@bluewin.ch>
> > wrote:
> >> It's something like that :

>
> > 'something like' is not what I'm looking for. Could you post the full
> > definitions? Just run SHOW CREATE TABLE <tablename>. It really saves time
> > to see the definitions and pinpoint it directly instead of trying to list
> > all possible reasons why this could/should fail.

>
> >> ALTER TABLE interaction ADD PRIMARY KEY (ID);

>
> > This is never in a CREATE TABLE syntax.
> > --
> > Rik Wasmus


You have defined the fields with a default value of 0. So if the
fields are not supplied for the insert or the supplied values are
NULL, the default will be used.
  Réponse avec citation
Vieux 19/12/2007, 14h04   #8
Rik Wasmus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: value by default 0

On Wed, 19 Dec 2007 14:53:35 +0100, Pierre Gilquin <inconnue@bluewin.ch>
wrote:

> This is the real one :
>
> The main table is Interaction
>
> SHOW CREATE TABLE interaction
> CREATE TABLE `interaction` (
> `audit_id` mediumint(9) default NULL,

........
> `impactValue` decimal(15,5) default NULL,
> PRIMARY KEY (`ID`),
> UNIQUE KEY `SUB1_SUB2_IDX`
> (`substance1Id`,`substance2Id`,`category`,`type`)
> ) TYPE=MyISAM
>
> CREATE TABLE `substance` (
> `AUC` decimal(15,5) default NULL,

..........
> `tempsRefAUC` decimal(15,5) default NULL,
> PRIMARY KEY (`id`),
> KEY `nomSubstance` (`nomLocal`)
> ) TYPE=MyISAM


You have no foreign key constraints (what makes you think you do?), and
further more foreign key constraints are not supported in the MyISAM
engine, you'll probably want to convert them to InnoDB.
--
Rik Wasmus
  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 07h17.


É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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16196 seconds with 16 queries