The stored procedure is easy to use, but it is difficult to read. It is not as easy to read as C # code.
The following describes the encoding rules of stored procedures.
Name of a stored procedure:
Module name_stored procedure name_proc
Example: job_addjob_proc
Pinyin cannot be used in the name of a stored procedure.
Note:
/*
Function: Function Description
Author: xumr
Created on:
Modified on: xumr added a restriction on name uniqueness.
Return Value:
--- 1: specific meaning
--- 2: specific meaning
...
--- Others: specific meaning
[If other stored procedures are called in this stored procedure]
Stored Procedure:
--- 1: job_isexist_proc
...
[If it is referenced by another stored procedure]
The stored procedure that applies the stored procedure:
--- 1: job_managejob_proc
Ideas:
--- 1: first determine whether the name is null
--- 2: second...
*/
Create proc job_addjob_prc
-- Parameter description
@ Parm1 as varchar (100 ),
-- Parameter description
@ Parm2 as varchar (50 ),
-- Parameter description
@ Parm3 as varchar (50 ),
-- Parameter description
@ Parm4 as int
As
2. Create procedure DBO. p_my_documentadd
(
@ Entid as char (10) Out,
@ Title as varchar (100 ),
@ Comment as text,
@ Hits as int,
@ Type as varchar (20 ),
@ Gender as tinyint
)
As
Begin
Begin tran -- start transaction
-- Generate a primary key
Exec p_my_gettablenextid 'document', 'D', 10, @ entid output // generate a primary key if no primary key is defined
Insert into document (
Entid,
Title,
Comment,
Hits,
Type,
Gender)
Values (
@ Entid,
@ Title,
@ Comment,
@ Hits,
@ Type,
@ Gender)
-- Error handling
If (@ error! = 0)
Begin
Raiserror 20000 'P _ my_documentadd: cannot insert data into p_my_documentadd' -- throws an error to the application
Rollback tran -- roll back the transaction
Return (1) -- set the return value
End
Commit tran -- commit a transaction if no error occurs
End