Is there a way to get the statement that created a view for an existing view in SQL Server 2008? I thought there was a stored procedure or some metadata that had this data, but
In case it helps someone in the future, here's a little script I put together to output the creation script for all views in a database.
DECLARE @definition varchar(max)
DECLARE @view CURSOR
SET @view = CURSOR FOR
SELECT m.definition FROM sys.views v INNER JOIN sys.sql_modules m ON m.object_id = v.object_id
OPEN @view
FETCH NEXT FROM @view INTO @definition
WHILE @@FETCH_STATUS = 0 BEGIN
PRINT @definition
PRINT 'GO'
FETCH NEXT FROM @view INTO @definition
END CLOSE @view DEALLOCATE @view