使用 SQL 直接从我的数据库中删除 CoreData 数据
有时,我需要从 CoreData 数据存储中删除 10,000 行,并且每次单独循环这些记录会花费太长时间。
有没有办法使用SQL直接从我的数据存储中快速删除?
There are times when i will need to delete say 10,000 rows from my CoreData data store and looping through those records individually each time takes way too long.
Is there a way to use SQL to directly delete from my data store quickly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
直接修改 CoreData 存储可能会损坏数据库,因此强烈建议不要这样做。最好的选择是使用 CoreData 查询进行删除,该查询能够一次选择要删除的所有行。
当我说它有损坏的风险时,我并不是说您的 SQL 查询会出现任何问题,而是 CoreData 还会将大量元数据插入到数据库中以帮助其建立索引。
Modifying the CoreData store directly risks corrupting the database and is very highly discouraged. Your best bet is to delete with a CoreData query that is able to select all of the rows to be deleted at once.
When I say it risks corrupting, I don't mean that anything would be wrong with your SQL query, but that CoreData also inserts a lot of metadata into the database to help its indexing.