TRUNCATE TABLE should respect CASCADE foreign keys
Imagine the following tables: Customers and Orders. Clearly, Orders are foreign key dependent on Customers. Therefore, we cannot truncate the Customers table in the current SQL Server product.
But what if the foreign key connecting the two tables was configured as ON DELETE CASCADE? Then, we could simply truncate both tables at once. This would not violate the foreign key. Basically, "TRUNCATE TABLE Orders" would be a faster way to execute "DELETE FROM Orders" and semantically do the same thing. I don't see why this would not work.
I propose that TRUNCATE TABLE automatically follows CASCADE delete relationships.
Upvotes: 1<=-=Mar 21 2017 1:07PM=-=>
Thank you for your feedback!
We will consider this feature for the future releases of SQL Server and Azure SQL Database.