You are here: Enforce integrity in PHP and MySQL « PHP SQL « IT news, forums, messages
Enforce integrity in PHP and MySQL

Posted by Rik on 05/07/06 15:10

Is it possible to enforce intergrity in linked tables in MySQL?
I'm not sure I've got the english wording right:

What is mean:
I've got:

table1.
id
field1
field2
etc...

table2
id
ref = table1.id
field1
field2
etc...

Now if I want to add a row to table2, ref must exists in table1.id. Is there
a MySQL setting for this I cannot see, or do have to create custom code to
check this?

Similarly, if I delete a row from table1, I want all rows from table2
deleted where ref = table1.id

I could offcourse create a table 'relations', containing:
id (autoincrement int)
table1 (varchar)
field1 (varchar)
relationship (enum('one-to-one','one-to-many'))
table2 (varchar)
field2 (varchar)
delete (int(1) (boolean, wether to delete related records))

And route all queries through a custom made database-object that checks the
table "relations" on every query and acts accordingly.

A MySQL setting that is set in the database (doesn't need to be called in
PHP script) would be preferred, but I can't find one.

Grtz,
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация