Encrypts all stored procedures of the current database.

Source: Internet
Author: User
Declare @ sp_name nvarchar (400)
Declare @ sp_content nvarchar (2000)
Declare @ asbegin int
Declare @ now datetime
Select @ now = getdate ()
Declare sp_cursor cursor
Select object_name (ID)
From sysobjects
Where xtype = 'P'
And type = 'P'
And crdate <@ now
And objectproperty (ID, 'ismsshipped ') = 0 open sp_cursorfetch next from sp_cursor
Into @ sp_namewhile @ fetch_status = 0
Begin
Select @ sp_content = text from syscomments where id = object_id (@ sp_name)
Select @ asbegin = patindex ('% as' + char (13) +' % ', @ sp_content)
Select @ sp_content = substring (@ sp_content, 1, @ asbegin-1)
+ 'With encryption'
+ Substring (@ sp_content, @ asbegin + 2, Len (@ sp_content ))
Select @ sp_name = 'drop procedure ['+ @ sp_name +']'
Exec sp_executesql @ sp_name
Exec sp_executesql @ sp_content
Fetch next from sp_cursor
Into @ sp_name
Endclose sp_cursor
Deallocate sp_cursor this stored procedure uses the sysobjects and syscomments tables, cleverly modifies the SQL definition statements of the original stored procedure, and changes the as to with encryption, the encrypted storage process is achieved. This stored procedure passes through SQL Server 2000

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.