CREATE PROCEDURE sp_employ
AS
select ID,Name,Picture,Time,Duty from employ
Go
而SQL語句:
select ID,Name,Picture,Time,Duty from employ where ID=10230
對應的存儲過程是:(用Alter替換我們已有的存儲過程)
ALTER PROCEDURE sp_employ
@inID int
AS
select ID,Name,Picture,Time,Duty from employ where ID=@inID
Go
下面對比一下SQL和存儲過程在ASP中的情況。首先看看直接執行SQL的情況:
<%
dim Conn, strSQL, rs
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password"
strSQL = " select ID,Name,Picture,Time,Duty from employ "
Set rs = Conn.Execute(strSQL)
%>
再看看如何執行Stored Procedure:
<%
dim Conn, strSQL, rs
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password" ’make connection
strSQL = "sp_employ"
Set rs = Conn.Execute(strSQL)
%>
而執行帶參數的Stored Procedure也是相當類似的:
<%
dim Conn, strSQL, rs, myInt
myInt = 1
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DSN=webData;uid=user;pwd=password"
strSQL = "sp_myStoredProcedure " & myInt
Set rs = Conn.Execute(strSQL)
%>
你可能覺得在ASP中使用存儲過程原來是這樣的簡單。對!就是這么簡單。