From what I understand you cannot do this.. Well that was quick, but I still need to do a truncate.
I have a soft spot for table variables, I really do. I almost exclusively use @tables for everything.
They wash my car, do my laundry and even make me coffee. I have a very close relationship with them. But why? Firstly, they are really quick. Quick to make, quick to use and quick to love. They have limitations, but hey I don’t mind, nobody’s perfect. And they work so well with Dynamic SQL, Leverage Table variables created outside of Dynamic SQL inside your Dynamic SQL.
That is all good and well, but how does it help me truncating the table? Let’s rather define what I want to do, I want to clean up the table, so if truncate does not work then let’s try
DELETE FROM @variable
Like a charm.
But which is all good and well, but what do I do with my IDENTITY column..
Simple, you cannot reset it and you cannot drop the table.. so:
Create another table
There is no need trying to faff about, if you are using a table variable you probably just need a quick and dirty fast table. So make another one.