日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

解讀為SQL Server數(shù)據(jù)庫傳數(shù)組參數(shù)的變通辦法_Mssql數(shù)據(jù)庫教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:詳解MSSQL的安全設置問題
目前SQL INJECTION的攻擊測試愈演愈烈,很多大型的網(wǎng)站和論壇都相繼被注入。這些網(wǎng)站一般使用的多為SQL SERVER數(shù)據(jù)庫,正因為如此,很多人開始懷疑SQL SERVER的安全性。其實SQL SERVER 2000已經(jīng)通過了美國政府的C2級安全認證-這是該行業(yè)所能擁有的最高認證級

最近一直在做Dnn模塊的開發(fā),過程中碰到這么一個問題,需要同時插入N條數(shù)據(jù),不想在程序里控制,但是SQL Sever又不支持數(shù)組參數(shù).所以只能用變通的辦法了.利用SQL Server強大的字符串處理傳把數(shù)組格式化為類似"1,2,3,4,5,6"。

然后在存儲過程中用SubString配合CharIndex把分割開來

詳細的存儲過程

CREATE PROCEDURE dbo.ProductListUpdateSpecialList

@ProductId_Array varChar(800),

@ModuleId int

AS

DECLARE @PointerPrev int

DECLARE @PointerCurr int

DECLARE @TId int

Set @PointerPrev=1

set @PointerCurr=1

begin transaction

Set NoCount ON

delete from ProductListSpecial where ModuleId=@ModuleId

Set @PointerCurr=CharIndex(',',@ProductId_Array,@PointerPrev+1)

set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev,@PointerCurr-@PointerPrev) as int)

Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)

SET @PointerPrev = @PointerCurr

while (@PointerPrev+1 < LEN(@ProductId_Array))

Begin

Set @PointerCurr=CharIndex(',',@ProductId_Array,@PointerPrev+1)

if(@PointerCurr>0)

Begin

set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev+1,@PointerCurr-@PointerPrev-1) as int)

Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)

SET @PointerPrev = @PointerCurr

End

else

Break

End

set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev+1,LEN(@ProductId_Array)-@PointerPrev) as int)

Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)

Set NoCount OFF

if @@error=0

begin


commit transaction

end

else

begin

rollback transaction

end

GO

網(wǎng)友Bizlogic對此的改進方法:

應該用SQL2000 OpenXML更簡單,效率更高,代碼更可讀:

CREATE Procedure [dbo].[ProductListUpdateSpecialList]

(

@ProductId_Array NVARCHAR(2000),

@ModuleId INT

)

AS

delete from ProductListSpecial where ModuleId=@ModuleId

-- If empty, return

IF (@ProductId_Array IS NULL OR LEN(LTRIM(RTRIM(@ProductId_Array))) = 0)

RETURN

DECLARE @idoc int

EXEC sp_xml_preparedocument @idoc OUTPUT, @ProductId_Array

Insert into ProductListSpecial (ModuleId,ProductId)

Select

@ModuleId,C.[ProductId]

FROM

OPENXML(@idoc, '/Products/Product', 3)

with (ProductId int ) as C

where

C.[ProductId] is not null

EXEC sp_xml_removedocument @idoc

 

分享:解讀改善SQL Server內存管理的問題
最近,為了能在數(shù)據(jù)庫服務器中運行其他應用程序,在保持數(shù)據(jù)庫操作系統(tǒng)版本不變的前提下對數(shù)據(jù)庫服務器進行了軟、硬件上的升級。在軟件上,將操作系統(tǒng)從Windows 2000升級到Windows Server 2003;在硬件上,將服務器中的內存由原來的512MB增加到1GB(1024MB)。

來源:模板無憂//所屬分類:Mssql數(shù)據(jù)庫教程/更新時間:2009-11-15
相關Mssql數(shù)據(jù)庫教程