資料庫預存程序(Procedure),預存程序procedure

來源:互聯網
上載者:User

資料庫預存程序(Procedure),預存程序procedure
預存程序的優點:預存程序的種類:

  • 系統預存程序

  • 使用者自訂預存程序

  • 擴充預存程序

預存程序的格式:
-- Template generated from Template Explorer using:-- Create Procedure (New Menu).SQL---- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below.---- This block of comments will not be included in-- the definition of the procedure.-- ================================================SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author:      <Author,,Name>-- Create date: <Create Date,,>-- Description: <Description,,>-- =============================================CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>     -- Add the parameters for the stored procedure here    <@Param1, sysname, @p1> <Datatype_For_Param1, , int> = <Default_Value_For_Param1, , 0>,     <@Param2, sysname, @p2> <Datatype_For_Param2, , int> = <Default_Value_For_Param2, , 0>ASBEGIN    -- SET NOCOUNT ON added to prevent extra result sets from    -- interfering with SELECT statements.    SET NOCOUNT ON;    -- Insert statements for procedure here    SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>ENDGO

預存程序是編譯好的SQL語句,而SQL語句如果寫在代碼中,需要及時編譯,然後才能運行,是在運行時編譯的,這就增加了時間,也增加了用戶端和伺服器之間的網路流量。

不使用預存程序用戶端和伺服器端的通訊次數:

使用預存程序用戶端和伺服器通訊次數:

使用預存程序後用戶端和伺服器之間的通訊次數就會減少,伺服器只傳回一個執行成功與否的參數就可以。

什麼情況下使用預存程序?
  • 對資料庫進行複雜操作時;

  • 需要最佳化,提高軟體運行速度時;

  • 當對軟體的安全性要求比較高時;

編譯好的預存程序可以讓很多人重複使用,何樂而不為!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.