PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > adding contraints FK refs to existing schema
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
adding contraints FK refs to existing schema

Réponse
 
LinkBack Outils de la discussion
Vieux 20/04/2006, 05h25   #1
awebguynow
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut adding contraints FK refs to existing schema

I've seen the syntax in the J. Stephens/C. Russell book and believe the
"alter table" would be:
ALTER TABLE tbl
[CONSTRAINT name] FOREIGN KEY (column_list)
REFERENCES tbl_name (column_list)
[ ON DELETE options ]
[ ON UPDATE options ]

the Syntax is really not a problem, and I'm pretty sure I won't be
violating any FK contraints right off the bat. If so, I expect the
Alter Table command will fail.

I've maintained this logically up to now, with emphasis on thought and
good design.
I'm ready to let the DB take over some of the heavy lifting where
things could go wrong.
Though I shy away from most "[visual] tools" I'm almost going to need
something to me manage this schema. ( any open-source tools ? )

btw, I'm using MySQL 5.0.17

I'm not a DBA, but I play one, when my boss is feeding me $$.
Any one had this experience? been in this dilemna? have a few battle
scars ?
and can save me the trouble ? I'm open to suggestions and tips.

  Réponse avec citation
Vieux 20/04/2006, 19h52   #2
Bill Karwin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: adding contraints FK refs to existing schema

awebguynow wrote:
> I've seen the syntax in the J. Stephens/C. Russell book and believe the
> "alter table" would be:
> ALTER TABLE tbl
> [CONSTRAINT name] FOREIGN KEY (column_list)
> REFERENCES tbl_name (column_list)
> [ ON DELETE options ]
> [ ON UPDATE options ]
>
> the Syntax is really not a problem, and I'm pretty sure I won't be
> violating any FK contraints right off the bat. If so, I expect the
> Alter Table command will fail.


I would recommend testing this for yourself. Create a parent & child
table in your "test" database (every MySQL installation has a test
database by default) and insert a few values that would violate such a
constraint. Then create the constraint. Does it fail?

In general, it's best to rely on yourself and do a small test to prove
that a given feature is going to work how you expect. People on
newsgroups can be wrong, and even the documentation can be wrong.

> I've maintained this logically up to now, with emphasis on thought and
> good design.
> I'm ready to let the DB take over some of the heavy lifting where
> things could go wrong.


Excellent! Keep in mind that in MySQL, foreign key constraints are
accepted but ignored if you use MyISAM tables. Only InnoDB tables
enforce constraints. Oh, and BDB tables, but nobody uses them.

> Though I shy away from most "[visual] tools" I'm almost going to need
> something to me manage this schema. ( any open-source tools ? )


MySQL AB offers a pretty nice GUI tool for schema design. It's called
MySQL Workbench. It's still in beta, but it works fairly well, as long
as you're on Windows.
http://dev.mysql.com/downloads/workbench/1.0.html

> I'm not a DBA, but I play one, when my boss is feeding me $$.
> Any one had this experience? been in this dilemna? have a few battle
> scars ?
> and can save me the trouble ? I'm open to suggestions and tips.


My tips are to read a lot, and make sure you keep a database where you
can experiment with new features before trying to apply them to your
real database.

"An expert is someone who has made every mistake."

Regards,
Bill K.
  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 07h10.


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