G
Guest
I'm using the store procedure below to drop and recreate all my views.
It works fine if the string is <=4000 characters.
I tried to change data type for @text parameter from nvarchar to ntext but
something is wrong. It occur error
Question.
How can I do to refresh (drop and re-recreate) all views including with
strings upper 4000 characters?
Procedures
-------------------------------------------------------
EXEC "T1_RefreshViews"
-------------------------------------------------------
ALTER PROCEDURE T1_RefreshViews
AS
SET NOCOUNT ON
DECLARE @name nvarchar(128)
DECLARE @text nvarchar(4000)
SELECT dbo.sysobjects.name, dbo.syscomments.text
INTO dbo.[#TempObjects]
FROM dbo.sysobjects INNER JOIN
dbo.syscomments ON dbo.sysobjects.id =
dbo.syscomments.id
WHERE (dbo.sysobjects.xtype = 'V') AND (dbo.sysobjects.category = 0)
ORDER BY dbo.sysobjects.name
DECLARE Object_Refresh CURSOR FOR SELECT name,text FROM #TempObjects
OPEN Object_Refresh
FETCH NEXT FROM Object_Refresh INTO @name,@text
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ('DROP VIEW ' + '"' + @name + '"')
EXEC (@text)
PRINT ('Droped and re-created ' + @name)
FETCH NEXT FROM Object_Refresh INTO @name,@text
END
CLOSE Object_Refresh
DEALLOCATE Object_Refresh
DROP TABLE #TempObjects
It works fine if the string is <=4000 characters.
I tried to change data type for @text parameter from nvarchar to ntext but
something is wrong. It occur error
Question.
How can I do to refresh (drop and re-recreate) all views including with
strings upper 4000 characters?
Procedures
-------------------------------------------------------
EXEC "T1_RefreshViews"
-------------------------------------------------------
ALTER PROCEDURE T1_RefreshViews
AS
SET NOCOUNT ON
DECLARE @name nvarchar(128)
DECLARE @text nvarchar(4000)
SELECT dbo.sysobjects.name, dbo.syscomments.text
INTO dbo.[#TempObjects]
FROM dbo.sysobjects INNER JOIN
dbo.syscomments ON dbo.sysobjects.id =
dbo.syscomments.id
WHERE (dbo.sysobjects.xtype = 'V') AND (dbo.sysobjects.category = 0)
ORDER BY dbo.sysobjects.name
DECLARE Object_Refresh CURSOR FOR SELECT name,text FROM #TempObjects
OPEN Object_Refresh
FETCH NEXT FROM Object_Refresh INTO @name,@text
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC ('DROP VIEW ' + '"' + @name + '"')
EXEC (@text)
PRINT ('Droped and re-created ' + @name)
FETCH NEXT FROM Object_Refresh INTO @name,@text
END
CLOSE Object_Refresh
DEALLOCATE Object_Refresh
DROP TABLE #TempObjects