The first computer room charging system-application of stored procedures

table of Contents

What is a stored procedure?

What are the benefits of using stored procedures?

How is the application in the computer room applied?

to sum up


What is a stored procedure?

It is a set of SQL statements to complete specific functions, which are compiled and stored in the database. Compile once, valid forever

 

What are the benefits of using stored procedures?

Reuse, reduce developer workload

The stored procedure only needs to be compiled when it is created, and every time this stored procedure is called in the future, it does not need to be compiled, and the general SQL statement is compiled every time it is executed, so the use of stored procedures can improve the execution speed of the database

 

How is the application in the computer room applied?

Friends, have you ever had such doubts when you knocked on the computer room? For example, SQL statements to query the cardno field in the student_Info table are used in many forms:

txtSQL="select * from student_Info where cardno= '" & txtcard.Text & "'"

Every time such a SQL statement is queried, it will take up our memory. Is there any way to reduce the memory occupied and the workload? Stored procedure can

Example application, as follows

The first step is to create a stored procedure in Microsoft SQL Server Management Studio 18

create proc proc_student1
@cardno varchar(10)
as
    select * from student_Info where cardno=@cardno

The second step is to call in the VB6 code

Example 1. In the top-up form: when you click OK, you need to determine whether the entered card number exists in the student_Info table

                              

 '调用存储过程proc_student1,查询卡号
stxtSQL = "exec proc_student1 @cardno = '" & txtcard.Text & "'"
Set srst = ExecuteSQL(stxtSQL, smsgText)
    
    '判断是否存在此卡号
    If srst.EOF Then                                  
        MsgBox "此卡号不存在或已经不再使用!", 0 + 48, "温馨提示"
        txtcard.Text = ""
        txtcard.SetFocus
        Exit Sub
    Else
        
        '更新student_Info表
    end if

 

Example 2. Application in the registration form: When you click the save button, judge whether the entered card number exists in the student_Info table

             

’调用存储过程,查询卡号
txtSQL = "exec proc_student1 @cardno = '" & txtcard.Text & "'"
Set rst = ExecuteSQL(txtSQL, msgText)
    
    ’判断是否有重复卡号
    If rst.EOF = False Then
        MsgBox "卡号已存在,请重新输入卡号!", 0 + 48, "温馨提示"
        txtcard.Text = ""
        txtcard.SetFocus
        Exit Sub
    Else

Look, is it convenient to create a stored procedure in SQL Server, so many forms can call it?

 

So if you query multiple conditions at the same time, can you use a stored procedure? The answer is definitely yes

Examples:

When checking out in the computer room, we need to select the operator or administrator in the drop-down box to check them out. When inquiring the table, we must also query the user id of the corresponding operator and administrator, and there is no checkout

        

 

What is it like in VB?

 '购卡
txtSQL = "select * from student_Info where UserID = '" & comboLavel.Text & "' and Ischeck = '" & "未结账" & "'"
Set rst = ExecuteSQL(txtSQL, msgText)

What if it is to use a stored procedure?

The first step: write a creation statement in SQL Server

ALTER proc p_recharge
@userid int,
@status varchar(10),
as
	select * from student_Info where UserID=@userid and status=@status

The second step: call in VB

txtSQL="exec p_recharge @userid= '" & comboLavel.Text & "' ,@status = '" & 未结账" "'"
set rst=ExecuteSQL(txtSQL, msgText)

 

to sum up

The storage process is like a brick, you can move it wherever you need it, which is convenient and doesn't take up space.

 

 

Guess you like

Origin blog.csdn.net/weixin_43319713/article/details/106343715