index是不用单独建一个field的。
从你的表结构和内容来看,可以建立多个索引。
比如id,type,userid.

解决方案 »

  1.   

    对不起,过了一星期才回来 ,这个问题好象有些眉目了,我再解释一下细节。我有两个主要的表,user 和 business, 各 自 记 载 了 用 户 的 所 有 信 息 。 由 於 交 税 和 admin 的 问 题 , 我 需 要 建 一 个 记 载 付 费 log的 表 , 否 则 每 天 我 们 会 收 到 当 天 的 帐 单 而 无 法 做 月 和 年 的 汇 总 , 我 们 希 望 通 过 这 个 表 来 省 人 工 。 由 於 是 半 路 出 家 , 我 对 数 据 库 了 解 的 不 深 , 特 别 是 这 些 key 和 关 联 , 更 不 用 说 深 的 话 题 like normalform and e-r map。 我 刚 搞 清 楚 index的 意 思 , 太 菜 了 , 别 骂 我 :)credit(表)
    1,id (unique id) (其 实 可 有 可 无 , 不 过 习 惯 上 每 个 表 我 都 写 这 个 id)
    2,type (b or u to present business or user) (区 分 用 户 是 来 自 商 家 还 是 用 户 )
    3, userid (business id or user id)???(商 家 和 用 户 的 各 自 唯 一 id, 和 第 二 条 type一 起 确 定 系 统 中 唯 一 的 用 户 )
    4, credit_card_name (visa, american express, etc)(信 用 卡 的 类 型 )
    5, credit_card_last4digits (信 用 卡 的 最 后 4位 数 )
    6, valid_until (信 用 卡 的 有 效 期 )
    7, amount (us$) (支 付 的 金 额 )
    8,timestamp (时 戳 )月 底 报 表 还 包 含 很 多 用 户 的 信 息 ,为 了 减 少 冗 余 , 我 通 过 2, 3条 查 出 唯 一 用 户 的 姓 名 , 地 址 , 邮 编 , 国 家 等 等 。 我 以 为 要 用 foreign key, 是 不 是 没 必 要 啊 ? 我 决 定 对 2,3做 index 加 速 查 询 , 时 戳 好 象 也 要 做 一 个 index。 说 我 分 得 不 细 , 是 因 为 信 用 卡 类 型 吧 ? 还 有 哪 些 缺 陷 , 请 多 指 教 。 with best wishessandy
      

  2.   

    forget to say, i only offer 20 score because I have no time to answer only questions to earn any, i expect to ask 20 questions by the account. I know the question is not very simple since it concerns db designing. it worths some hundred dollars actually. if you need more score, i could register an extra id and offer you 200 score :) i am very appreciate of your suggestion !with best wishessandy
      

  3.   

    #
    # Table structure for table 'finance_accounting'
    #DROP TABLE IF EXISTS `finance_accounting`;
    CREATE TABLE `finance_accounting` (
      `id` int(32) NOT NULL auto_increment,
      `type` char(1) NOT NULL default '',
      `user_id` int(32) NOT NULL default '0',
      `credit_card_name` tinyint(2) NOT NULL default '0',
      `credit_card_last4digits` tinyint(4) NOT NULL default '0',
      `valid_until` date NOT NULL default '0000-00-00',
      `amount` float(10,2) NOT NULL default '0.00',
      `timestamp` timestamp(14) NOT NULL,
      PRIMARY KEY  (`id`),
      KEY `key_timestamp` (`timestamp`),
      KEY `key_type_id` (`type`,`user_id`)
    ) TYPE=MyISAM;这 样 设 计 是 否 合 理 ? 先 谢 谢 啦 !
      

  4.   

    注意,如果你想使用事务等功能,数据库类型要设为InnoDB。
    另外,现在的mysql并不支持外键。
      

  5.   

    建议去了 id,这的确是一个不必要的字段,
    你还为它建立了主索引!
    这会很大的影响你的系统速度
    直接使用
    `user_id` int(32) NOT NULL default '0', 为主键,

    KEY `key_type_id` (`type`,`user_id`) 为主键另,有效期倒是可以做一个索引的
      

  6.   

    #数据库类型要设为InnoDB。
    thanks !#现在的mysql并不支持外键。
    i awared. :)#建议去了 id,
    这的确是一个不必要的字段,
    你还为它建立了主索引!
    这会很大的影响你的系统速度
    this is the most case I could not decide, ya, thanks a lot!I will try this KEY `key_type_id` (`type`,`user_id`) 为主键#,有效期倒是可以做一个索引的
    ? currently i have no idea how to handle the valid date. maybe just check whether it is later than current time? with best wishessandy