I want to add a foreign key in the CONSULT However, MySql reports the following error:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'REFERENCES doctor (crm)) ENGINE = InnoDB DEFAULT CHARSET = latin1' at line 9
The SQL code is written as follows:
CREATE TABLE 'medico' (
'crm' float(12) NOT NULL,
'cpf' varchar(15) DEFAULT NULL,
'dataInscricao' varchar(20) DEFAULT NULL,
'bairro' varchar(50) DEFAULT NULL,
'cidade' varchar(50) DEFAULT NULL,
'logradouro' varchar(90) DEFAULT NULL,
'uf' varchar(2) DEFAULT NULL,
'nome' varchar(50) DEFAULT NULL,
'nomeUser' varchar(12) DEFAULT NULL,
'senhaUser' varchar(12) DEFAULT NULL,
'cnpj' varchar(15) NOT NULL,
PRIMARY KEY ('crm')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE 'consulta' (
'codConsulta' int(11) NOT NULL,
'data' varchar(10) DEFAULT NULL,
'horario' varchar(10) DEFAULT NULL,
'crm' float(12) NOT NULL,
'cpf' varchar(15) NOT NULL,
'codTipoCons' int(11) NOT NULL,
PRIMARY KEY ('codConsulta'),
FOREIGN KEY 'crm' REFERENCES 'medico'('crm')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What is the problem?