2016-11-20 3 views
-1

У меня возникли проблемы с настройкой этих двух таблиц. Я получаю следующее сообщение об ошибке, связанной со вторым столом :Моя таблица sql получает сообщение об ошибке

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

Используйте явное определение 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.

Смежные вопросы