Doonie Darkoo
Doonie Darkoo

Reputation: 1495

Can we use Truncate function inside a function?

Can we use Truncate function inside a function ? I want to know if I execute TRUNCATE TABLE query in a function would it truncate the table ?

Upvotes: 1

Views: 626

Answers (1)

Thom A
Thom A

Reputation: 95830

TRUNCATE isn't a function, it's a DML operation. Functions in SQL Server (just like in C# and many other languages) are followed by parentheses; for example GETDATE(), ISNULL({NULLable Expression},{Return Expression if prior NULL}), dbo.DelimitedSplit8k_LEAD({Delimited List},{Delimiter character}), etc.

And no, you cannot use TRUNCATE inside a function. A Function cannot perform any DML operations apart from against table value variables that are declared within the function itself (and then you are using a multi-line function, which tend to perform poorly).

If you need to be performing DML operations, you want a Stored Procedure.

Upvotes: 4

Related Questions