Mysql 使用两个外键创建表

Mysql 使用两个外键创建表,mysql,sql,Mysql,Sql,我看过以前的文章。遵循它们,但这里给出了语法错误: create table temp (name varchar(20), id varchar(128), hash varchar(128), INDEX id, CONSTRAINT FOREIGN KEY (id) references user_record(userid), CONSTRAINT FOREIGN KEY (hash) references post_data(hash)); 错误:

我看过以前的文章。遵循它们,但这里给出了语法错误:

        create table temp (name varchar(20), id varchar(128), hash varchar(128),  
INDEX id, CONSTRAINT FOREIGN  KEY (id) references user_record(userid), CONSTRAINT 
FOREIGN KEY (hash) references post_data(hash));
错误:

     #1064 - You have an error in your SQL syntax; check the manual that corresponds 
to your MySQL server version for the right syntax to use near ' CONSTRAINT FOREIGN KEY (id) 
references user_record(userid), CONSTRAINT FOREIGN ' at line 1

错误在哪里?

请参见下面的示例,这可能会有所帮助: 这是一个用户表:

CREATE TABLE user(
userid INTEGER(8),
email VARCHAR(30),
password VARCHAR(30),
createdat datetime,
PRIMARY KEY(userid));

CREATE TABLE profile(
userid INTEGER(8),
firstname VARCHAR(20),
middlename VARCHAR(20),
lastname VARCHAR(20),
city VARCHAR(20),
state VARCHAR(20),
country VARCHAR(20),
zip INTEGER(5),
PRIMARY KEY(userid),
INDEX(userid),
CONSTRAINT FOREIGN KEY(userid) REFERENCES user(userid));

CREATE TABLE tags(
tagid INTEGER(8),
tagname VARCHAR(40),
PRIMARY KEY(tagid));

CREATE TABLE notes(
notesid INTEGER(8),
notes VARCHAR(50),
CONSTRAINT FOREIGN KEY(userid) REFERENCES user(userid),
CONSTRAINT FOREIGN KEY(tagid) REFERENCES tags(tagid));
您试图在子表中将其设为外键的键应在父表中将其作为主键。否则,您可能会出错


祝你好运

查询中的语法错误与索引部分有关

更改:

INDEX id,
致:


谢谢,我的子表中的FK是父表中的PK。您能看到任何语法错误吗?您能提供您的父表,以便清楚地发现错误吗
INDEX (id),