delete 语句

最近更新时间:2024-07-24 17:02:21

我的收藏

带条件删除

```sql
select * from tbase;
id
nickname
2
TBase 好
1
Hello TBase
3

4
TBase good
delete from tbase where id=4;
null 条件的表达方式
delete from tbase where nickname is null;
select * from tbase;
id
nickname
2
TBase 好
1
Hello TBase

多表关联删除数据

set prefer_olap to on;
delete from tbase using t_appoint_col where tbase.id=t_appoint_col.id;
select * from tbase;
id
nickname
2
TBase 好

返回删除数据

delete from tbase returning *;
id
nickname
2
TBase 好

删除所有数据

insert into tbase select t,random()::text from generate_series(1,100000) as t;
truncate table tbase;