... loại extend stored
procedure được xem như system storedprocedure và ngược lại.
5. Remote StoredProcedure : Những storedprocedure gọi stored
procedure ở server khác.
Viết Stored Procedure
... một stored procedure.
Chúng ta hãy xem một ví dụ sau về Stored Procedure: Ðể tạo một stored
procedure bạn có thể dùng Enterprise Manager click lên trên StoredProcedure
-> New StoredProcedure ... TemporaryStoredProcedure : Là những storedprocedure tương tự
như local storedprocedure nhưng chỉ tồn tại cho đến khi connection đã tạo
ra chúng bị đóng lại hoặc SQL Server shutdown. Các stored procedure...
... sql;
command.Parameters.AddWithValue("@Ma",txtMaHS.Text.Trim());
command.Parameters.AddWithValue("@Ten",txtTenHS.Text.Trim());
command.Parameters.AddWithValue("@Ns",dtNgaySinh.Value);
command.Parameters.AddWithValue("@Dc",txtDiaChi.Text.Trim());
command.Parameters.AddWithValue("@Diem",txtDiemTB.Text.Trim());
command.Parameters.AddWithValue("@Lop",cboLop.SelectedValue.ToString());
command.ExecuteNonQuery();
5. Thực thi thông qua các Stored procedure
a. Cách tạo Stored Procedure
- Tạo mới Stored Procedure, chọn New
Stored Procedure
6
... dụng được cách thực thi
các câu lệnh SQL thông qua Stored Procedure.
o StoredProcedure không có kết
quả trả về (parameter input)
o StoredProcedure có kết quả trả
về (parameter output)
2. ... dẫn thực hành NMCNPM
o Chọn Next
o Chọn các table muốn import vào
CSDL SQL Server. Sau đó chọn Next.
4
Hướng dẫn thực hành NMCNPM
- Tạo StoredProcedure thêm mới thông
tin một học sinh như...
... F2 Q10
Return
9. Using VB 6 or VB.NET to execute the ‘AddNewOrder’ storedprocedure
10. Using xp_cmdshell extended storedprocedure to send a message
(xp_cmdshell ‘net send Hello’)
Tungvn40@yahoo.com ...
VALUES(@OrderID,@ProductName,@CustomerID)
SELECT @Result=0
COMMIT TRANSACTION
END
END
Else
BEGIN
If Exists (SELECT OrderID FROM [Orders] WHERE
OrderID=@OrderID)
BEGIN
SELECT @Result=1
ROLLBACK TRANSACTION
END
Else
BEGIN
INSERT INTO ...
VALUES(@CustomerID,@CustomerName)
If Exists (SELECT OrderID FROM [Orders] WHERE
OrderID=@OrderID)
BEGIN
SELECT @Result=1
ROLLBACK TRANSACTION
END
Else
BEGIN
INSERT INTO [Orders]
(OrderID,ProductName,CustomerID)...
... the data in the
temporary table before each call to the stored procedure:
truncate table #results
You should also drop the temporarytable after all test cases have been run:
drop table #results
A ... temporary table. Then, call the storedprocedure under test and retrieve the
returned rowset into the temporary table. Compute the aggregate checksum of the temporary
table and compare against an ... from a table. To test such stored procedures, you need to compare actual and
expected values of the object acted upon by the stored procedure. This situation is very similar
to testing stored procedures...
... extend storedprocedure được xem như system storedprocedure và ngược lại.
5. Remote StoredProcedure : Những storedprocedure gọi storedprocedure ở server
khác.
6.4.3. Viết Stored Procedure
Tên ... một stored procedure. Chúng ta hãy xem một ví dụ
sau về Stored Procedure: Ðể tạo một storedprocedure bạn có thể dùng Enterprise Manager
click lên trên StoredProcedure -> New StoredProcedure ... Ngoài ra storedprocedure có
thể được encrypt (mã hóa) để tăng cường tính bảo mật.
6.4.2. Các Loại StoredProcedure
Stored procedure có thể được chia thành 5 nhóm như sau:
1. System Stored Prcedure...
... from the
Executing SELECT Statements and TableDirect Commands
A TableDirect command is actually a SELECT statement that returns all the rows and
columns for a specified table. A Command object ... SQL SELECT statements,
TableDirect commands or storedprocedure calls
that return a result set. Returns the result set in a
DataReader object.
ExecuteScalar() object Used to execute SQL SELECT ... SqlConnection mySqlConnection =
new SqlConnection(
"server=localhost;database=Northwind;uid=sa;pwd=sa"
);
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();
mySqlCommand.CommandText...
... extend storedprocedure được xem như system storedprocedure và
ngược lại.
5. Remote StoredProcedure : Những storedprocedure gọi storedprocedure ở
server khác.
6.4.3. Viết Stored Procedure
Tên ... một stored procedure. Chúng
ta hãy xem một ví dụ sau về Stored Procedure: Ðể tạo một storedprocedure bạn có thể
dùng Enterprise Manager click lên trên StoredProcedure -> New Stored
Procedure ... Return
Ðể tạo ra một storedprocedure ta dùng lệnh CREATE PROCEDURE theo sau
là tên của nó (nếu là temporarystoredprocedure thì thêm dấu # trước tên của procedure.
Nếu muốn encrypt...
... property of the
mySqlCommand object to a SELECT that uses the COUNT() function. This SELECT
returns the number of rows in the Products table:
mySqlCommand.CommandText =
" ;SELECT COUNT(*) ... mySqlCommand to a
SELECT statement that uses the FOR XML AUTO clause. This SELECT statement
returns the first five rows from the Products table as XML.
mySqlCommand.CommandText =
" ;SELECT ... // read the DataTable containing the schema from the DataReader
DataTable myDataTable = productsSqlDataReader.GetSchemaTable();
// display the rows and columns in the DataTable
foreach...
... contains the stored procedure.
4. Expand the Stored Procedures node.
5. Right-click on the storedprocedure to be debugged and select Step IntoStored
Procedure from the popup menu.
6. If requested, ... Step IntoStored
Procedure from the popup menu.
2. If requested, supply the parameter values on the Run StoredProcedure dialog.
Debugging a storedprocedure from managed code
To debug a stored ... Run StoredProcedure dialog.
Alternatively, if the storedprocedure is already open in a source window in Visual Studio
.NET:
1. Right-click on the storedprocedure to be debugged and select...
... this routine, called UseAStoredProcedureWithAParameter, in Listing A.8.
Listing A.8 basCommandExamples.vb: Calling a StoredProcedure By Using
Parameters
Sub UseAStoredProcedureWithAParameter(ByVal ... which in this case will
be the name of the stored procedure, called CustOrdersHist. You can see the T-SQL for
CustOrderHist in Listing A.7. This storedprocedure returns product names and the total ... A.7 Northwind SQL Server Database: T-SQL for the StoredProcedure
Called CustOrdersHist
ALTER PROCEDURE CustOrderHist @CustomerID nchar(5)
AS
SELECT ProductName, Total=SUM(Quantity)
FROM Products...
... from a SQL Server storedprocedure to a calling
application using the RAISERROR (note the spelling) function. The error message
severity levels are listed in Table 2-12
.
Table 2-12. RAISERROR ... SqlInfoMessageEventHandler(conn_InfoMessage);
// Define a storedprocedure command and the parameters.
SqlCommand cmd = new SqlCommand("SP0210_Raiserror", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Severity", ... function, look up RAISERROR in SQL
Server Books Online.
[ Team LiB ]
// Try to execute the stored procedure.
cmd.ExecuteNonQuery( );
}
catch(System.Data.SqlClient.SqlException ex)
{...
... a data value to the storedprocedure and the storedprocedure to
pass a data value back to the caller.
Output
The parameter is an output parameter allowing the storedprocedure to
pass a ... a single stored procedure, as shown in Example 2-14
:
SP0212_ReturnValueWithDataReader
Returns a result set containing all records from the Orders table in Northwind. The
stored procedure ... LiB ]
[ Team LiB ]
Recipe 2.12 Retrieving StoredProcedure Return Values Using a DataReader
Problem
You are using a storedprocedure to create a DataReader and need to get the return...
... sau về Stored Procedure: Ðể tạo một
stored procedure bạn có thể dùng Enterprise Manager click lên trên StoredProcedure -> New
Stored Procedure Trong ví dụ này ta sẽ tạo ra một storedprocedure ... extend storedprocedure được xem như system storedprocedure
và ngược lại.
Viết StoredProcedure
Tên và những thông tin về StoredProcedure khi được tạo ra sẽ chứa trong SysObjects table còn ... Local storedprocedure thường được viết bởi DBA hoặc
programmer. Chúng ta sẽ bàn về cách tạo stored prcedure loại này trong phần kế tiếp.
* TemporaryStoredProcedure : Là những stored procedure...
... single stored procedure.
Solution
Use OpenXML with an XMLdocument representing a DataSet of the changes made.
The schema of table TBL0811 used in this solution is shown in Table 8-10
.
Table ... xmlns:mp="urn:schemas-microsoft-com:xml-metaprop">
The system storedprocedure sp_xml_removedocument removes the internal
representation of an XML document specified by a document handle obtained
from the system storedprocedure sp_xml_preparedocument ... not supplied, the results are returned in an edge
table format representing the XML document structure in a single table.
The system storedprocedure sp_xml_preparedocument reads XML as input...
... for the storedprocedureinto a Parameters
collection. The collection is iterated over to extract information about the parameters,
which is subsequently displayed.
If the storedprocedure ... System stored procedure: sp_sproc_columns
The second technique is specific to Microsoft SQL Server. The system storedprocedure
sp_sproc_columns returns parameter information for one or more stored ... return results for
more than one storedprocedure at a time. It also supports filtering options and does not
require a storedprocedure Command object. Executing this procedure returns a result set...