sql - Which IDs from a database to use? -


i have 2 sql tables, , b. each table has primary key id. table b has field x (which may null) refers id of (if not null).

then need list (stored in file) of identifiers of objects stored in table a.

which ids suggest use, a.id or b.id in list? (it clear having id of row in b can infer id of row in a, provided row in b has non-null x.)

[added] clear: object partially stored in , partially in b.

[added] structure of tables (z_users b, z_clients a, z_users.client field x):

 create table `z_users` (   `id` int(10) unsigned not null auto_increment,   `password` varchar(255) collate utf8_bin not null,   `fullname` varchar(255) collate utf8_bin not null,   `phone` varchar(255) collate utf8_bin not null,   `address` text collate utf8_bin not null,   `email` varchar(255) collate utf8_bin default null,   `admin` enum('false','true') collate utf8_bin not null default 'false',   `worker` int(10) unsigned default null,   `client` int(10) unsigned default null,   primary key  (`id`),   unique key `worker` (`worker`),   unique key `client` (`client`),   unique key `email` (`email`) ) engine=innodb  default charset=utf8 collate=utf8_bin;  create table `z_clients` (   `id` int(10) unsigned not null auto_increment,   `company` text collate utf8_bin not null,   `shortdesc` text collate utf8_bin not null,   `site` varchar(255) collate utf8_bin not null,   `affair` varchar(255) collate utf8_bin not null,   primary key  (`id`) ) engine=myisam  default charset=utf8 collate=utf8_bin; 

use business key (natural key) of table. it's unwise persist surrogate key outside database because creates hidden dependency - if surrogate key refactored or values changed data outside database becomes invalid or references wrong value.

each of tables appears have 1 key , isn't clear me business key(s) supposed in case.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -