Data room charging system-storage process and charging system storage process
A lot of things have been learned in this IDC charging system. E-R diagrams, views, stored procedures, triggers and more. All these things have been learned before, and this application has doubled in practice.
Benefits of using Stored Procedures
1. The stored procedure is compiled only when it is created. You do not need to re-compile the stored procedure every time you execute it. Generally, the SQL statement is compiled every time it is executed, therefore, using stored procedures can speed up database execution.
2. When performing complex operations on the database (for example, performing Update, Insert, Query, and Delete operations on multiple tables ), this complex operation can be encapsulated in a stored procedure and used together with the transaction processing provided by the database.
3. The process can be reused to reduce the workload of database developers.
4. High completeness. You can set that only some users have the right to use the specified stored procedure.
Practical application of Stored Procedures
I used the stored procedure in the back-to-card operation. The following uses the Back-to-card operation as an example.
Create a stored procedure
<Span style = "font-family: KaiTi_GB2312; font-size: 18px;"> create procedure proc_CloseCard -- create a stored procedure @ cardId varchar (10), @ closeCardUserId varchar (10) -- Define asbegin -- insert data into t_CloseCard (cardId, closeCash, registryDate, registryTime, isChecked, registryUserId) into the return table select cardId, balance, date, time, isChecked, userId from t_card where cardId = @ cardId -- delete related cards from the card table delete from t_card where cardId = @ cardId -- update the card return table update t_closecard set closeuserId = @ closeCardUserId where cardId = @ cardId end </span>
Calling the stored procedure at Layer D of the card return
<Span style = "font-family: KaiTi_GB2312; font-size: 18px; "> '<summary> 'add backoff information' </summary>' <param name =" _ enCloseCardEntity "> return True if the card is inserted successfully., false is returned for failure </returns> Public Function AddCloseCard (ByVal enCloseCardEntity As CloseCardEntity) as Boolean Dim sqlHelper As New SQLHelper 'instantiate SQLHelper 'SQL statement Dim plain text As String = "proc_CloseCard"' to define the command type. The Stored Procedure Dim primitive type As CommandType primitive type = CommandType. storedProcedure 'defines the parameter array Dim sqlParams As SqlParameter ()' and assigns sqlParams = {New SqlParameter ("@ cardId", enCloseCardEntity to the parameter array. cardId), New SqlParameter ("@ closeCardUserId", SharedUserId. userId)} Return sqlHelper. executeNoQuery (plain text, plain type, sqlParams) End Function </span>The results of operations with stored procedures are the same as those with SQL statements. Only one SQL statement is written on the database and one is written on the Compilation end.
After using it, you will find that the stored procedure is actually quite simple. However, the speaker said that the stored procedure is process-oriented and does not conform to the object-oriented idea. It will be used less in the future. But now in the learning stage, it is also good to use, at least to use. Make continuous progress in practice.