android - SQLite : how to organize my data base

标签 android mysql database organization

我有一个简单的 Android 应用程序,想知道组织数据库表 (mysql) 的最佳方式。 该应用程序的想法是一个类别列表,然后用户按下其中一个类别,他会获得另一个项目列表,当他单击其中一个项目时,他会获得有关该项目的详细信息。

例如,第一个列表(国家)有(英国、美国、中国、日本等国家)

您点击“美国”,您会得到另一个列表(州)(加利福尼亚州、纽约州、亚利桑那州...)

您点击加利福尼亚州,即可获取其详细信息(人口、面积、首都)

如果您依次单击“英国”和“伦敦”,也会发生同样的情况...

那么,我应该如何安排我的数据,我应该这样做:

  1. 一张表代表国家/地区,另一张表代表每个国家/地区,

  2. 只有一张大表包含所有州,并且有一列说明它属于哪个国家/地区。

  3. 还有其他建议吗?

最佳答案

尝试如下操作..然后从那里开始..

create table countries (
  id int(11) not null auto_increment,
  name varchar(255) not null,
  primary key (id)
);<p></p>

<p>create table states (
  id int(11) not null auto_increment,
  name varchar(255) not null,
  country_id int(11) not null,
  primary key (id)
  constraint foreign key (country_id) references countries(id) on delete cascade
);</p>

<p>create table properties (
  name varchar(255) not null,
  primary key (name)
);</p>

<p>create table state_properties (
  id int(11) not null auto_increment,
  property varchar(255) not null,
  state_id int(11) not null,
  primary key(id),
  constraint foreign key (property) references properties(property) on delete cascade,
  constraint foreign key (state_id) references states(id) on delete cascade
);
</p>

已编辑:拼写错误

关于android - SQLite : how to organize my data base,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094463/

相关文章:

android - 有什么方法可以将 JSON 字符串转换为 android 中的查询字符串?

java - 无法从 Fragment 访问 TextView

Android:Android Service 强制应用程序运行缓慢

mysql - 查询批量删除 WordPress 中的成员

sql-server - 将 SQL Server 数据库合并为 1

java - okHttp 不会取消执行

mysql - 在 mysql5 中创建更新操作触发器时出错?

mysql - 无法在/usr/local/bin/mysql_config执行mysql_config

database - 防止 PostgreSQL 有时选择错误的查询计划

database - 将数据从一个列传输到不同表中的不同列