I create a – view in sql server.
I want to alter the view every time that a – row is added to my table .
I create trigger for it :
CREATE TRIGGER Trigger1
ON dbo.Table1
AFTER INSERT
AS
BEGIN
ALTER VIEW VIEW1 as
SELECT *
From Table1
END
But I get the error : ‘ALTER VIEW’ must be the only statement in the batch.
What should I do to correct it error ?
WHY do you want to alter your view every time a row is inserted? That doesn’t make any sense at all!
The view doesn’t contain (or store) the rows it shows – it’s just a stored query…
It will always go to the base table and fetch the data again, when you select from it. There’s really no need to constantly alter the view!
It will show that row after it’s been inserted without being altered…