Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

根据ER图编写的SQl语句,不知道对不对

图片描述

CREATE TABLE `d_radio_info` (
  `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '通讯扩展信息ID',
  `sn` VARCHAR(20) NOT NULL COMMENT '设备SN',
  `imei` CHAR(15) NOT NULL COMMENT '国际移动设备身份码',
  PRIMARY KEY (`id`),
  UNIQUE KEY `sn` (`sn`),
  CONSTRAINT `t_radio_info_ibfk_1` FOREIGN KEY (`sn`) REFERENCES `t_device` (`sn`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='RADIO信息表';

CREATE TABLE `t_site` (
  `s_id` INT(11) NOT NULL AUTO_INCREMENT,
  `site_name` VARCHAR(20) DEFAULT NULL,
  `phonenumber` VARCHAR(20) DEFAULT NULL,
  PRIMARY KEY (`s_id`)
) ENGINE=INNODB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8;

CREATE TABLE `t_device` (
  `d_id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '设备ID',
  `sn` VARCHAR(20) NOT NULL COMMENT '设备序列号',
  `model_id` BIGINT(20) NOT NULL COMMENT '型号ID',
  `status` TINYINT(2) NOT NULL DEFAULT '0' COMMENT '设备状态 0:正常1:不正常',
  `s_id` INT(11) NOT NULL ,
  `remainder` VARCHAR(20) DEFAULT NULL ,
  PRIMARY KEY (`d_id`),
  UNIQUE KEY `sn` (`sn`),
  CONSTRAINT `d_device_ibfk_2` FOREIGN KEY (`s_id`) REFERENCES `t_site` (`s_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT='设备表';

CREATE TABLE `sendata` (
  `se_id` INT(11) NOT NULL AUTO_INCREMENT,
  `suwd`  VARCHAR(4) DEFAULT NULL,
  `suyl`  VARCHAR(4) DEFAULT NULL,
  `jsll`  VARCHAR(4) DEFAULT NULL,
  `jstds` VARCHAR(4) DEFAULT NULL,
  `cstds` VARCHAR(4) DEFAULT NULL,
  `ph`    VARCHAR(4) DEFAULT NULL,
  `yl`    VARCHAR(4) DEFAULT NULL,
  `ylv`   VARCHAR(4) DEFAULT NULL,
  `ycy`   VARCHAR(4) DEFAULT NULL,
  `zd`    VARCHAR(4) DEFAULT NULL,
  `rjy`    VARCHAR(4) DEFAULT NULL,
  `d_id`  BIGINT(20) NOT NULL,
  `sentem` VARCHAR(20) DEFAULT NULL,
  PRIMARY KEY (`se_id`),
  CONSTRAINT `sendata_ibfk_2` FOREIGN KEY (`d_id`) REFERENCES `t_device` (`d_id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

数据库新手,不管是ER图还是代码都很挫,望大神指正~~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Er图表述关系已经很明显了,我觉得细心,应该不会出错。我就是有一点不太一样。我现实中很少使用,外键。我都是在程序上实现。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...