我在设置这两个表时遇到问题。我收到与 第二个表 相关的以下错误消息:
1064 - 您的SQL语法出错;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便使用附近的' COMMENT' FOREIGN KEY引用cliCommand记录', 示例文本评论'在第4行
CREATE TABLE cliCommand
(
cliCommandId INT(11) PRIMARY KEY NOT NULL COMMENT 'Auto_Increment primary key used for interal purposes' AUTO_INCREMENT,
code ENUM('CI', 'LX', 'MO', 'SQ', 'UX', 'WI') NOT NULL COMMENT 'Command unique code shared with users to enable search using this code.',
os ENUM('CiscoIOS', 'Linux', 'macOS', 'SQL', 'Unix', 'Windows') NOT NULL COMMENT 'Operating Systems this command works with',
title TEXT NOT NULL COMMENT 'command short description/title to be displayed in search result listing along with command code and os',
tag TEXT COMMENT 'any other meta data associated with command'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Keeps all cli commands with meta data & description';
CREATE TABLE commandExample
(
commandExampleId INT(11) PRIMARY KEY NOT NULL COMMENT 'Autoincrement key for internal purposes' AUTO_INCREMENT,
`_cliCommandId` INT(11) REFERENCES cliCommand(cliCommandId) COMMENT 'FOREIGN KEY referencing to cliCommand record',
example TEXT COMMENT 'an example associated with this command, there could be multiple examples associated with a command, each as a new record in this table'
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Keeps examples, if any, for a command to be displayed';
答案 0 :(得分:0)
使用明确的constraint
定义。我不认为MySQL支持内联外键引用:
CREATE TABLE commandExample
(
commandExampleId INT(11) PRIMARY KEY NOT NULL COMMENT 'Autoincrement key for internal purposes' AUTO_INCREMENT,
`_cliCommandId` INT(11) COMMENT 'FOREIGN KEY referencing to cliCommand record',
example TEXT COMMENT 'an example associated with this command, there could be multiple examples associated with a command, each as a new record in this table',
constraint fk_clicommand_clicommand foreign key (_cliCommandId) REFERENCES cliCommand(cliCommandId)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Keeps examples, if any, for a command to be displayed';
Here是SQL Fiddle的一个例子。