日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件下載最安全的下載網(wǎng)站、值得信賴的軟件下載站!

      首頁西西教程數(shù)據(jù)庫教程 → 什么是存儲過程?Sql 存儲過程知識詳解

      什么是存儲過程?Sql 存儲過程知識詳解

      相關(guān)軟件相關(guān)文章發(fā)表評論 來源:西西整理時間:2013/1/2 20:01:07字體大。A-A+

      作者:西西點擊:0次評論:3次標簽: 存儲過程

      3 頁 創(chuàng)建存儲過程

       創(chuàng)建存儲過程

      UserAccount
      UserIDUserNamePassWordRegisterTimeRegisterIP
      126                   6                   2012-12-316
      185                   5                   2013-01-015
      191                   1                   2013-01-011
      202                   2                   2013-01-012
      213                   3                   2013-01-013
      224                   4                   2013-01-014
      235                   5                   2013-01-015
      257                   7                   2013-01-017
      268                   8                   2013-01-018
      NULLNULLNULLNULLNULL

      針對上面的表,我使用存儲過程對它做一些操作:

      1. 只返回單一記錄集的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      create Procedure GetUserAccount
      as
      select * from UserAccount
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      exec GetUserAccount

       結(jié)果:相當于運行 select * from UserAccount 這行代碼,結(jié)果為整個表的數(shù)據(jù)。

      2.沒有輸入輸出的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure inUserAccount
      as
      insert into UserAccount (UserName,[PassWord],RegisterTime,RegisterIP) values(9,9,'2013-01-02',9)
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec inUserAccount

       結(jié)果:相當于運行 insert into UserAccount (UserName,[PassWord],RegisterTime,RegisterIP) values(9,9,'2013-01-02',9) 這行代碼。

      3.有返回值的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure inUserAccountRe
      as
      insert into UserAccount (UserName,[PassWord],RegisterTime,RegisterIP) values(10,10,'2013-01-02',10)
      return @@rowcount
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec inUserAccountRe

       解釋:這里的@@rowcount為執(zhí)行存儲過程影響的行數(shù),執(zhí)行的結(jié)果是不僅插入了一條數(shù)據(jù),還返回了一個值即 return value =1  ,這個可以在程序中獲取,稍后在c#調(diào)用存儲過程中會有說到。

      4.有輸入?yún)?shù)和輸出參數(shù)的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure GetUserAccountRe
      @UserName nchar(20),
      @UserID int output
      as
      if(@UserName>5)
      select @UserID=COUNT(*) from UserAccount where UserID>25
      else
      set @UserID=1000
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec GetUserAccountRe '7',null

       解釋:@UserName為輸入?yún)?shù),@UserID為輸出參數(shù)。 運行結(jié)果為@userID為COOUT(*)即 =1。

      5. 同時具有返回值、輸入?yún)?shù)、輸出參數(shù)的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure GetUserAccountRe1
      @UserName nchar(20),
      @UserID int output
      as
      if(@UserName>5)
      select @UserID=COUNT(*) from UserAccount where UserID>25
      else
      set @UserID=1000
      return @@rowcount
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec GetUserAccountRe1 '7',null

       結(jié)果:@userID為COOUT(*)即 =1,Retun Value=1。

      6.同時返回參數(shù)和記錄集的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure GetUserAccountRe2
      @UserName nchar(20),
      @UserID int output
      as
      if(@UserName>5)
      select @UserID=COUNT(*) from UserAccount where UserID>25
      else
      set @UserID=1000
      select * from UserAccount
      return @@rowcount
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec GetUserAccountRe2 '7',null

       結(jié)果:返回執(zhí)行 select * from UserAccount 這句代碼的結(jié)果集,同時@userID為COOUT(*)即 =1,Retun Value=9。 

      7.返回多個記錄集的存儲過程 

      -------------創(chuàng)建名為GetUserAccount的存儲過程----------------
      
      create Procedure GetUserAccountRe3
      as
      select * from UserAccount
      select * from UserAccount where UserID>5
      go
      
      -------------執(zhí)行上面的存儲過程----------------
      
      exec GetUserAccountRe3

       結(jié)果:返回兩個結(jié)果集,一個為 select * from UserAccount,另一個為 select * from UserAccount where UserID>5 。

      小結(jié):上面我們創(chuàng)建了各式的存儲過程,下面看我們在c#中怎樣調(diào)用這些存儲過程。

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(3)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)