I get the error “Incorrect syntax near the keyword ‘truncate’.” and not sure what’s wrong with the syntax here, it’s not obvious to me…probably something stupid but I need another set of eyes:
ALTER VIEW [dbo].[vw_All_Events]
AS
truncate table Event
Select [event_id]
,[site_id]
,[autogenerated]
,[creation_date]
,[last_update_date]
from Event
GO
A view only allows a single statement after the
ASand it must be data retrieval (return a rowset). It can’t be a different type including data definition, data modification, procedural, declarative, or any other.You can do these things with a stored procedure, or a user-defined function (but can’t do DDL & DML in a function).
In detail, a stored procedure allows flow-of-control statements like IF THEN ELSE BEGIN END WHILE RETURN. You can use DML to UPDATE, DELETE and INSERT. You can use DDL to CREATE and DROP tables and indexes, add columns and constraints, and so on. You can return multiple rowsets. You can execute dynamic SQL.
What are you trying to accomplish?