免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1340 | 回复: 3
打印 上一主题 下一主题

【已解决】建表语句求助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-08 18:11 |只看该作者 |倒序浏览
本帖最后由 chinafenghao 于 2012-11-09 10:47 编辑

mysql> create table trains(tid integer not null,ttype varchar(10) not null,startstation integer not null,endstation integer not null,primary key(tid) constraint startstation foreign key trains(startstation) references stations(sid) on delete restrict on update restrict,constraint endstation foreign key trains(endstation) references stations(sid) on delete restrict on update restrict);
ERROR 1064 (42000): 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 startstation foreign key trains(startstation) references stations(sid' at line 1

why?
how to solve?

论坛徽章:
2
技术图书徽章
日期:2013-10-30 14:37:252015年亚洲杯之伊朗
日期:2015-04-30 13:37:02
2 [报告]
发表于 2012-11-08 21:41 |只看该作者
create table trains(tid integer not null,ttype varchar(10) not null,startstation integer not null,endstation integer not null,primary key(tid) ,constraint startstation foreign key trains(startstation) references stations(sid) on delete restrict on update restrict,constraint endstation foreign key trains(endstation) references stations(sid) on delete restrict on update restrict);

omitted a comma(',') between 'primary key(tid)' and 'constraint startstation..'@lfsyue

论坛徽章:
8
CU大牛徽章
日期:2013-09-18 15:20:48CU大牛徽章
日期:2013-09-18 15:20:58CU大牛徽章
日期:2013-09-18 15:21:06CU大牛徽章
日期:2013-09-18 15:21:12CU大牛徽章
日期:2013-09-18 15:21:17天秤座
日期:2013-10-30 14:01:03摩羯座
日期:2013-11-29 18:02:31luobin
日期:2016-06-17 17:46:36
3 [报告]
发表于 2012-11-09 10:46 |只看该作者
本帖最后由 chinafenghao 于 2012-11-09 10:46 编辑

@lfsyue
楼上已经说了,你pk后面少了逗号。
DROP TABLE IF EXISTS  trains;
CREATE TABLE trains (
  tid INTEGER NOT NULL,
  ttype VARCHAR (10) NOT NULL,
  startstation INTEGER NOT NULL,
  endstation INTEGER NOT NULL,
  PRIMARY KEY (tid) ,
  CONSTRAINT fk_startstation FOREIGN KEY  (startstation) REFERENCES stations(sid) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT fk_endstation FOREIGN KEY  (endstation) REFERENCES stations (sid) ON DELETE RESTRICT ON UPDATE RESTRICT
)ENGINE=INNODB ;

DROP TABLE IF EXISTS stations;
CREATE TABLE stations (
id INT(11) NOT NULL AUTO_INCREMENT,
sid INT(11) NOT NULL,
PRIMARY KEY(id),
UNIQUE KEY (sid)
);

论坛徽章:
0
4 [报告]
发表于 2012-11-14 16:12 |只看该作者
1楼应该好好学学chinafenghao,你发上来的语句看着就纠结,还是看着fenghao发的语句比较清晰。回复 1# lfsyue


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP