欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SQL多表联合删除

程序员文章站 2022-06-01 16:46:46
...
/*
Navicat MySQL Data Transfer

Source Server         : localhost
Source Server Version : 50548
Source Host           : localhost:3306
Source Database       : test

Target Server Type    : MYSQL
Target Server Version : 50548
File Encoding         : 65001

Date: 2016-10-02 16:23:04
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `table1`
-- ----------------------------
DROP TABLE IF EXISTS `table1`;
CREATE TABLE `table1` (
  `id` int(11) NOT NULL,
  `table2_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `fk_table2_idx` (`table2_id`),
  CONSTRAINT `fk_table2` FOREIGN KEY (`table2_id`) REFERENCES `table2` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of table1
-- ----------------------------
INSERT INTO `table1` VALUES ('3', '1');
INSERT INTO `table1` VALUES ('5', '2');

-- ----------------------------
-- Table structure for `table2`
-- ----------------------------
DROP TABLE IF EXISTS `table2`;
CREATE TABLE `table2` (
  `id` int(11) NOT NULL,
  `name` varchar(45) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of table2
-- ----------------------------
INSERT INTO `table2` VALUES ('1', 'jam');
INSERT INTO `table2` VALUES ('2', 'tubo');
INSERT INTO `table2` VALUES ('3', 'nan');

 

转载于:https://my.oschina.net/milize/blog/758918