SQL Server metadata

Source: Internet
Author: User

Integrated instance

The following describes a stored procedure, which automatically encrypts the user stored procedure of the current database.

Declare @ sp_name nvarchar (400)
Declare @ sp_content nvarchar (2000)
Declare @ asbegin Int
Declare @ now datetime
Select @ now = getdate ()
Declare sp_cursor Cursor For
Select object_name (ID)
From sysobjects
Where xtype = 'P'
And type = 'P'
And crdate <@ now
And objectproperty (ID, 'ismsshipped ') = 0
Open sp_cursor
Fetch Next from sp_cursor
Into @ sp_name
While @ 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)
+' Encryption As'
+ 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
End
Close sp_cursor
Deallocate sp_cursor

The stored procedure uses the sysobjects and syscomments tables, cleverly modifies the SQL definition statements of the original stored procedure, and modifies the as to with encryption as, thus achieving the purpose of encrypting the stored procedure. This stored procedure is passed on SQL Server 2000.

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.