PostgreSQL 多表关联删除

柔情只为你懂 2022-12-04 07:44 223阅读 0赞

用PostgreSQL数据库删除某个表数据 student,需要关联多个表(如classroom)作为条件,以下语句走不通:

  1. delete s.* from student s,classroom c where s.cid = c.id and s.sid = 1
  2. delete from student s,classroom c where s.cid = c.id and s.sid = 1

上面两种写法操作后提示报错,下面是PostgreSQL数据库对多表关联删除的正确用法,多张表之间用using连接:

  1. delete FROM student s using classroom c where s.cid = c.id and s.sid = 1

发表评论

表情:
评论列表 (有 0 条评论,223人围观)

还没有评论,来说两句吧...

相关阅读

    相关 PostgreSQL定时删除数据

    背景 有时候我们需要定时删除一些表数据比如一些log表,只需要存储7天的数据,如果用程序,比如java来处理。就需要写一个定时器来处理,比较麻烦。比较方便简单的做法就是使