tags:

views:

20

answers:

1
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 ;

This is my table sql, i use navicat to design my database, why it writes KEY instead of FOREIGN KEY?

A: 

The KEY keyword is a synonym for INDEX in MySQL. You do not have a foreign key constraint specified in that CREATE TABLE command.

The CREATE TABLE syntax:

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)
Daniel Vassallo
Ohh thanks. your shoot is goal.
kamil
@kamil: I'm glad it helped. You may want to mark the answer as accepted if it was helpful. You can do this by clicking on the green tick on the left of the answer :)
Daniel Vassallo