Golang GORM 单表删除

删除只有一个操作,delete。也是先找到再去删除。 可以删除单条记录,也可以删除多条记录。

Golang GORM 单表删除_第1张图片

	var s Student
	db.Debug().Delete(&s, "age = ?", 100)
	fmt.Println(s)

[15.878ms] [rows:1] DELETE FROM `student` WHERE age = 100
	var s Student
	db.Debug().Take(&s, "age = ?", 101)
	db.Debug().Delete(&s)

[2.060ms] [rows:1] SELECT * FROM `student` WHERE age = 101 LIMIT 1

[4.494ms] [rows:1] DELETE FROM `student` WHERE `student`.`id` = 1  

你可能感兴趣的:(Golang,Gorm,golang)