两张表,一张是用户帐号表,一张是用户信息表,两张表是一对一关系,我想让他们做级联删除
也就是我删除用户帐号表的一条信息,会自动删除信息表的对应一条信息
同样在信息表删除一条信息也自动在帐号表删除对应的一条信息这语句要怎么写啊
也就是我删除用户帐号表的一条信息,会自动删除信息表的对应一条信息
同样在信息表删除一条信息也自动在帐号表删除对应的一条信息这语句要怎么写啊
解决方案 »
- 一服务器JSP与MYSQL连接问题,实在解决不了,求助!
- mysql 不支持中文字符查询
- 一个简单的SQL
- WEB系统操作一段时间就连接不上,数据库mysql
- [求助]新手,MYSQL语句执行出错,在线等答案,这是MYSQL的BUG?
- 最近刚看mysql,对于产生无重复编号算法有个想法,我用伪码表示,各位看看执行效率和空间存储效率怎么样
- sql server2000数据导入mysql问题
- 请问如何在windows下同时运行两个不同版本的mysql?
- 为什么我在mysql.user中插入了一个用户,如下:
- 请问有没有带用户认证的PHPMyAdmin?
- mysql的datatime类型是否精确到毫秒?
- 急!触发器"stack depth limit exceeded"错误是咋回事啊?
CREATE PROCEDURE A()
BEGIN
declare exit handler for sqlexception rollback;
BEGIN TRANSACTION;
delete from A where A.userid=100;
delete from B where B.usetid=100;
COMMIT;
end;
create table tx1 (id int primary key,col int) engine=innodb;
create table tx2 (id int primary key,fid int,foreign key (fid) references tx1(id) on delete cascade) engine=innodb;insert into tx1 values (1,1),(2,2);
insert into tx2 values (11,1),(12,2);
mysql> create table tx1 (id int primary key,col int) engine=innodb;
Query OK, 0 rows affected (0.06 sec)mysql> create table tx2 (id int primary key,fid int,foreign key (fid) reference
s tx1(id) on delete cascade) engine=innodb;
Query OK, 0 rows affected (0.14 sec)mysql> select * from tx1;
+----+------+
| id | col |
+----+------+
| 1 | 1 |
| 2 | 2 |
+----+------+
2 rows in set (0.00 sec)mysql> select * from tx2;
+----+------+
| id | fid |
+----+------+
| 11 | 1 |
| 12 | 2 |
+----+------+
2 rows in set (0.00 sec)mysql> delete from tx1 where id=2;
Query OK, 1 row affected (0.03 sec)mysql> select * from tx1;
+----+------+
| id | col |
+----+------+
| 1 | 1 |
+----+------+
1 row in set (0.00 sec)mysql> select * from tx2;
+----+------+
| id | fid |
+----+------+
| 11 | 1 |
+----+------+
1 row in set (0.00 sec)mysql>