|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
虽然可以将一个droptable语句转换成先delete再删表,性能却会降低很多。这里我们用上面说道的另外一种可用数据:“操作前数据备份”。
http://searchdatabase.techtarget.com/tip/1,289483,sid13_gci837799,00.html
ThisSPwilldecryptStoredProcedures,ViewsorTriggersthatwereencryptedusing"withencryption".ItisadaptedfromascriptbyJosephGamaandShoeBoy.Therearetwoversions:oneforSPsonlyandtheotheroneforSPs,triggersandviews.Forversion1,theinputisobjectname(storedprocedure,viewortrigger),andforversion2,theinputisobjectname(storedprocedure,viewortrigger),objecttype(T-trigger,P-storedprocedureorV-view).FromPlanetSourceCode.com.
createPROCEDUREsp_decrypt_sp(@objectNamevarchar(50))ASDECLARE@OrigSpText1nvarchar(4000),@OrigSpText2nvarchar(4000),@OrigSpText3nvarchar(4000),@resultspnvarchar(4000)declare@iint,@tbigint--getencrypteddataSET@OrigSpText1=(SELECTctextFROMsyscommentsWHEREid=object_id(@objectName))SET@OrigSpText2=ALTERPROCEDURE+@objectName+WITHENCRYPTIONAS+REPLICATE(-,3938)EXECUTE(@OrigSpText2)SET@OrigSpText3=(SELECTctextFROMsyscommentsWHEREid=object_id(@objectName))SET@OrigSpText2=CREATEPROCEDURE+@objectName+WITHENCRYPTIONAS+REPLICATE(-,4000-62)--startcounterSET@i=1--filltemporaryvariableSET@resultsp=replicate(NA,(datalength(@OrigSpText1)/2))--loopWHILE@i<=datalength(@OrigSpText1)/2BEGIN--reverseencryption(XORoriginal+bogus+bogusencrypted)SET@resultsp=stuff(@resultsp,@i,1,NCHAR(UNICODE(substring(@OrigSpText1,@i,1))^(UNICODE(substring(@OrigSpText2,@i,1))^UNICODE(substring(@OrigSpText3,@i,1)))))SET@i=@i+1END--droporiginalSPEXECUTE(dropPROCEDURE+@objectName)--removeencryption--preservecaseSET@resultsp=REPLACE((@resultsp),WITHENCRYPTION,)SET@resultsp=REPLACE((@resultsp),WithEncryption,)SET@resultsp=REPLACE((@resultsp),withencryption,)IFCHARINDEX(WITHENCRYPTION,UPPER(@resultsp))>0SET@resultsp=REPLACE(UPPER(@resultsp),WITHENCRYPTION,)--replaceStoredprocedurewithoutenryptionexecute(@resultsp)GO
ReaderFeedback
JoakimM.writes:Itriedthisscriptwithmixedresults.Itworksforsomeencryptedprocedures,butforothersIgeterrormeassageslike:
Server:Msg512,Level16,State1,Proceduresp_decrypt_sp,Line7.Subqueryreturnedmorethan1value.Thisisnotpermittedwhenthesubqueryfollows=,!=,<,<=,>,>=orwhenthesubqueryisusedasanexpression.
KarlCwrites:IgotthesamemessageasJoakimM.butuponfurtherinvestigationIfoundthatthishappensonlywhenstoredproceduresexceed4000characters.Whenthishappens,SQLServerstorestheprocedureacrossmultiplerowssoyougettheerrorsubqueryreturnemorethan1row.Togetaroundthatyoucanchangethestatement
SELECTctextFROMsyscommentsWHEREid=object_id(@objectNametoSELECTtop1ctextFROMsyscommentsWHEREid=object_id(@objectNameorderbycolid
Thatwillgetyouthefirstpartofthestoredprocedure,whichcantbecreatedbecauseitismissingtheendpartandisnotavalidsyntaxbutyoucanprint@resultspouttoseeit.
ForMoreInformation
Feedback:E-mailtheeditorwithyourthoughtsaboutthistip.Moretips:HundredsoffreeSQLServertipsandscripts.Tipcontest:HaveaSQLServertiptoofferyourfellowDBAsanddevelopers?Thebesttipssubmittedwillreceiveacoolprize--submityourtiptoday!BestWebLinks:SQLServertips,tutorials,scripts,andmore.Forums:AskyourtechnicalSQLServerquestions--orhelpoutyourpeersbyansweringthem--inouractiveforums.AsktheExperts:OurSQL,DatabaseDesign,Oracle,SQLServer,DB2,metadata,anddatawarehousinggurusarewaitingtoansweryourtoughestquestions.对于insert操作,只需要把event_type改成DELETE_ROWS_EVENT;对于delete操作,改成WRITE_ROWS_EVENT |
|