8 个解决方案
#1
create table test(
id int,
name char(20),
foreign key(id) references XXtable(id) );
#2
不行啊!比如说我已经有两个表了,student和subject,student中的subjectid要与subjcet表中id相关联,sql语句该怎么写啊?
#3
create table subject(
id int(4) not null,
name char(20),
primary key(id)) type = innodb;
create table student(
subjectid int(4) not null,
index(subjectid),
sex varchar(20),
foreign key(subjectid) references subject(id))type=innodb;
1.类型为innodb
2.要创建索引
id int(4) not null,
name char(20),
primary key(id)) type = innodb;
create table student(
subjectid int(4) not null,
index(subjectid),
sex varchar(20),
foreign key(subjectid) references subject(id))type=innodb;
1.类型为innodb
2.要创建索引
#4
也可以使用可视化工具 navicat不错哦
#5
直接在mysql中建立不就搞定了
#6
我的意思是这样的,这两个表在数据库中都已经存在了,现在就是要把student中的subjectid和subject中的id关联起来,我用mysql前端搞,报错:
想用sql语句实现,该怎么实现,不用再建表了啊!
想用sql语句实现,该怎么实现,不用再建表了啊!
#7
alter table student add constraint stu_sub_fk foreign key (subjectid) references subject(id);
#8
up
#1
create table test(
id int,
name char(20),
foreign key(id) references XXtable(id) );
#2
不行啊!比如说我已经有两个表了,student和subject,student中的subjectid要与subjcet表中id相关联,sql语句该怎么写啊?
#3
create table subject(
id int(4) not null,
name char(20),
primary key(id)) type = innodb;
create table student(
subjectid int(4) not null,
index(subjectid),
sex varchar(20),
foreign key(subjectid) references subject(id))type=innodb;
1.类型为innodb
2.要创建索引
id int(4) not null,
name char(20),
primary key(id)) type = innodb;
create table student(
subjectid int(4) not null,
index(subjectid),
sex varchar(20),
foreign key(subjectid) references subject(id))type=innodb;
1.类型为innodb
2.要创建索引
#4
也可以使用可视化工具 navicat不错哦
#5
直接在mysql中建立不就搞定了
#6
我的意思是这样的,这两个表在数据库中都已经存在了,现在就是要把student中的subjectid和subject中的id关联起来,我用mysql前端搞,报错:
想用sql语句实现,该怎么实现,不用再建表了啊!
想用sql语句实现,该怎么实现,不用再建表了啊!
#7
alter table student add constraint stu_sub_fk foreign key (subjectid) references subject(id);
#8
up