sqldatatypes - correct mysql data type for column that contain multiple index ids -
in sql have table (trades) contains list of trades
each trade has id.
i have table (companies) contains list of companies, in table there trades column, in here there id's trades, there more 1 trade.
what best data type trades column in companies table?
sorry if terminology isn't correct!
to keep atomarity (modularity) of data items in tables , flexibility of future select queries (joins, grouping, searching , etc.) best practice have table have fields keeps relation of these data items. have many-to-many relation.
here example:
-- create syntax table 'companies' create table `companies` ( `id` int(11) unsigned not null auto_increment, `name` varchar(100) not null, primary key (`id`) ) engine=innodb default charset=utf8; -- create syntax table 'trades' create table `trades` ( `id` int(11) unsigned not null auto_increment, `name` varchar(100) not null, primary key (`id`) ) engine=myisam default charset=utf8; -- create syntax table 'companies_trades' create table `companies_trades` ( `company_id` int(11) unsigned not null, `trade_id` int(11) unsigned not null, primary key (`company_id`,`trade_id`) ) engine=myisam default charset=utf8;
Comments
Post a Comment