简体   繁体   English

SQL Server DELETE中更好的性能

[英]Better performance in SQL Server DELETE

I'm trying to delete specific rows from various tables by id in my database, and I have too many tables to delete from, for example: 我正在尝试通过数据库中的ID从各种表中删除特定行,并且我有太多表要删除,例如:

DELETE FROM [Customers] 
WHERE [id] = @Id

DELETE FROM [Agents]
WHERE [id] = @Id

DELETE FROM [Policy] 
WHERE [id] = @Id

DELETE FROM [Issues]
WHERE [id] = @id

DELETE FROM [Refunds] 
WHERE [id] = @Id

EXEC SP_DeleteCustomerRelations @Id
EXEC SP_DeleteAgentComplaints @Id

DELETE FROM [dbo].[Complaints]
WHERE id = @Id

I was wondering if there anyway to enhance the performance of this SQL query? 我想知道是否仍然可以提高此SQL查询的性能?

Or is there anyway to not repeat DELETE? 还是反正不重复删除? As it takes up to 10 seconds deleting from all these rows from tables. 从表格中删除所有这些行最多需要10秒钟。

Are these Tables in relation of parent/child means is that ID is PK of one table and used as a FK in the other ones. 这些表是否与父/子关系是ID是一个表的PK,而在另一个表中用作FK。 If it is the scenerio you can use the cascading here means when ID is deleted from the parent table it will automatically get deleted from the child tables. 如果是Scenerio,则可以在此处使用级联,这意味着当从父表中删除ID时,它将自动从子表中删除。 See this link for How to use Cascade Delete . 有关如何使用级联删除的信息,请参见此链接。

Hope this helps please let me know if it doesnt helps. 希望这会有所帮助,如果没有帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM