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 > Selective inserts or something?!?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Selective inserts or something?!?

Réponse
 
LinkBack Outils de la discussion
Vieux 17/09/2007, 16h06   #1 (permalink)
SomeDude
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Selective inserts or something?!?

Hi group,

I have 3 tables: tblOne, tblTwo and tblThree.

All of my items are stored in tblOne. However, based on the item-type
information must be added in either tblTwo or tblThree (not both).

Is there some way to force this behaviour? For example, when I try to add
an item with type 'Two' information has to be written to tblTwo?

Right now, my application enforces this logic but I would like to put
that responsibility in the database.

TIA,

SomeDude

  Réponse avec citation
Vieux 19/09/2007, 03h07   #2 (permalink)
Michael Austin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Selective inserts or something?!?

SomeDude wrote:
> Hi group,
>
> I have 3 tables: tblOne, tblTwo and tblThree.
>
> All of my items are stored in tblOne. However, based on the item-type
> information must be added in either tblTwo or tblThree (not both).
>
> Is there some way to force this behaviour? For example, when I try to add
> an item with type 'Two' information has to be written to tblTwo?
>
> Right now, my application enforces this logic but I would like to put
> that responsibility in the database.
>
> TIA,
>
> SomeDude
>


Triggers would normally be used to handle this...

Example modified from
http://dev.mysql.com/doc/refman/5.0/...e-trigger.html

Given:
insert into t1 (c1, c2, c3, c4, c5) values (1,2,3,4,5);

DELIMITER |
CREATE TRIGGER testref AFTER INSERT ON t1
FOR EACH ROW BEGIN
if new.c2 = 2
then
INSERT INTO t2 (c3) values (NEW.c1);
end if;
if new.c2 = 3
then
INSERT INTO t3 set c3 = NEW.c1;
end if;
END;
|
DELIMITER ;

Yeah, the data here makes no sense- but you get the idea.
  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 10h46.


Édité par : vBulletin® version 3.7.2
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,07666 seconds with 10 queries