为什么navicat在CREATE TABLE中写入密钥而不是外键?

时间:2010-09-29 22:20:34

标签: mysql

CREATE TABLE IF NOT EXISTS `trl_bill` (
  `bill_id` int(11) NOT NULL AUTO_INCREMENT,
  `fee` double NOT NULL DEFAULT '0',
  `begin_date` date NOT NULL,
  `end_date` date NOT NULL,
  `is_paid` tinyint(4) NOT NULL DEFAULT '0',
  `request_id` int(11) NOT NULL,
  PRIMARY KEY (`bill_id`),
  KEY `request_id` (`request_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED AUTO_INCREMENT=1 ;

这是我的表sql,我使用navicat设计我的数据库,为什么它写KEY而不是FOREIGN KEY

1 个答案:

答案 0 :(得分:0)

KEY关键字是MySQL中INDEX的同义词。您没有在foreign key constraint命令中指定CREATE TABLE

CREATE TABLE语法:

CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name
    { LIKE old_tbl_name | (LIKE old_tbl_name) }
create_definition:
    col_name column_definition
  | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)
      [index_option] ...
  | {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
      [index_name] [index_type] (index_col_name,...)
      [index_option] ...
  | {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] FOREIGN KEY
      [index_name] (index_col_name,...) reference_definition
  | CHECK (expr)