Cs_censorship_createupdatedelete // cs_censorships_get

Source: Internet
Author: User
Cs_censorship_createupdatedelete -- Audit System creation, update, and deletion
Alter proc [DBO]. cs_censorship_createupdatedelete -- Audit System creation update Deletion
(/** // * Refers to some restricted words, such as fuck */
@ Word nvarchar (40)
, @ Deleteword bit = 0
, @ Replacement nvarchar (40)
, @ Settingsid int
)
As
SET transaction isolation level read uncommitted
/** // * Sets the transaction isolation level. Read uncommitted performs dirty read or 0 isolation locks, which means no shared lock is issued,
The exclusive lock is also not accepted. When this option is set, uncommitted read or dirty read can be performed on the data.
Change the value in the data, and the row can also appear in the dataset or disappear from the dataset. The role of this option and all
Set nolock to the same for all tables in the statement. This is the minimum limit among the four isolation levels. */
Set nocount on
/** // * When set nocount is on, no count is returned (the number of rows affected by the transact-SQL statement ).
When set nocount is off, return the count. Update even when set nocount is on
@ Rowcount function. */

If (@ deleteword> 0)
Begin
Delete from
Cs_censorship
Where
WORD = @ word and settingsid = @ settingsid
Return
/** // * Delete a record */
End
Else
Begin
Update cs_censorship set
Replacement = @ replacement
Where
WORD = @ word and settingsid = @ settingsid
/** // * Update and replace the content. For example, the content is replaced by ***, And the content is replaced by another one */
If (@ rowcount = 0) -- if the number of affected rows is 0
Begin
Insert into cs_censorship (
Word, replacement, settingsid
) Values (
@ Word, @ replacement, @ settingsid
)
/** // * Insert a new restricted word */
End
End

Cs_censorships_get
Alter proc [DBO]. cs_censorships_get
(
@ Word nvarchar (40) = '',
@ Settingsid int
)
As
SET transaction isolation level read uncommitted
/** // * Sets the transaction isolation level. Read uncommitted performs dirty read or 0 isolation locks, which means no shared lock is issued,
The exclusive lock is also not accepted. When this option is set, uncommitted read or dirty read can be performed on the data.
Change the value in the data, and the row can also appear in the dataset or disappear from the dataset. The role of this option and all
Set nolock to the same for all tables in the statement. This is the minimum limit among the four isolation levels. */

Select
*
From
Cs_censorship
Where
Settingsid = @ settingsid and (WORD = @ word or (@ word = ''and 1 = 1 ))
/** // * Query the qualified records-_ =! I don't understand why I still add 1 = 1. I always feel that the first 1 is better than the second 1.
It seems to be a little bigger. Is it l or I in upper case? When I did not say .*/



Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.