Sometimes I make weird rookie mistakes when working with SQL and one of them is confusing syntax of various commands. Today it was truncate.
So the syntax is
Truncate table table_name;
It doesn't have a where clause and is used to remove the entire data. On the other hand when we use delete, the syntax can be
Delete from table_name;
It will delete the entire data, but we can also use a where clause.
Delete from table_name where column_name = criteria;
I was using truncate table table_name where date = cast(getdate() as date);
Wouldn't work and will definitely fail.
Sugandh
No comments:
Post a Comment