SQL Server update view stored procedure function script

Source: Internet
Author: User

--视图、存储过程、函数名称 DECLARE @ NAME NVARCHAR(255); --局部游标 DECLARE @CUR CURSOR --自动修改未上状态为旷课 SET @CUR= CURSOR SCROLL DYNAMIC FOR SELECT NAME FROM DBO.SYSOBJECTS      WHERE NAME NOT IN ( ‘SYSCONSTRAINTS‘ , ‘SYSSEGMENTS‘ )          AND          (              OBJECTPROPERTY(ID, N ‘IsView‘ ) = 1               --视图              OR OBJECTPROPERTY(ID,N ‘IsProcedure‘ ) = 1        --存储过程              OR OBJECTPROPERTY(ID,N ‘IsScalarFunction‘ ) = 1   --标量函数              OR OBJECTPROPERTY(ID,N ‘IsTableFunction‘ ) = 1    --标题函数              OR OBJECTPROPERTY(ID,N ‘IsInlineFunction‘ ) = 1   --内联函数          ); OPEN @CUR; FETCH NEXT FROM @CUR INTO @ NAME WHILE (@@FETCH_STATUS=0) BEGIN      DECLARE @OldText NVARCHAR( MAX );      DECLARE @NewText NVARCHAR( MAX );      --读取创建脚本,当脚本超长时分成多条记录时合并      SELECT @[email protected] + CHAR (10) + CHAR (13) + RTRIM(TEXT) FROM SYSCOMMENTS WHERE ID = OBJECT_ID(@ NAME );      --将创建脚本替换为更新脚本      SET @NewText= REPLACE (@OldText,N ‘CREATE VIEW‘ ,N ‘ALTER VIEW‘ );      SET @NewText= REPLACE (@NewText,N ‘CREATE PROCEDURE‘ ,N ‘ALTER PROCEDURE‘ );      SET @NewText= REPLACE (@NewText,N ‘CREATE FUNCTION‘ ,N ‘ALTER FUNCTION‘ );           BEGIN TRY          EXEC (@NewText);      END TRY      BEGIN CATCH          PRINT N ‘---------------------------------------------------------------------------‘ ;          PRINT @ NAME + N ‘ : ‘ + ERROR_MESSAGE();          --PRINT @OldText;          PRINT N ‘---------------------------------------------------------------------------‘ ;      END CATCH      FETCH NEXT FROM @CUR INTO @ NAME END CLOSE @CUR; DEALLOCATE @CUR;

SQL Server update view stored procedure function script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.