-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLServer: ExecuteDelete without Where should translate to TRUNCATE TABLE #34957
Comments
Plenty of reasons why this is fundamentally different.
|
Yeah, I tend to agree with @Bretttt and @cincuranet on this - IIRC there are some observable difference between the two. For example, unless I'm mistaken, identity columns are reset by TRUNCATE but not by DELETE... For cases where there are observable differences, it's probably better to also keep the .NET user-facing API distinct so that everything is clear and predictable, rather than having a weird thing where just adding/removing a Where clause suddenly leads to behavioral differences... @Bretttt's point about TRUNCATE not returning rows is also good and points in the direction of a separate API. We can indeed add an API here, though this really is an extremely simply command to do via SQL Note previous discussion on introducing TRUNCATE to EF in #5972. |
Also, TRUNCATE requires higher rights than READ or WRITE |
lol, clearly I’m not a SQL Server expert. I don’t think there’s much value in having a method for this. ExecuteSqlCommand is sufficient for cases where you can use it and need the perf. Not returning the affected rows, requiring ALTER TABLE permissions, and not running DELETE triggers are definitely deal-breakers for the general case. |
@bricelam yeah, I agree... There's the slight advantage of not having to hardcode the table name (or get it from the model), but that doesn't seem worth it... As there seems to be consensus that there isn't enough value here, I'll go ahead and close for now. |
Today, the following statement...
...translates to the following on SQL Server.
But it would be more performant to use a truncate statement.
The text was updated successfully, but these errors were encountered: