field values from the cursor to the variable
While
@ Fetch_status
=
0
--
Process items in a loop
Begin
Update
Ta
Set
Ty
=
Ty
-
@ Tbqty
Where
PID
=
@ PID
Fetch
Next
From
Cur_1
Into
@ PID
,
@ Tbqty
If
@ Error
>
0
-If an error occurs
Begin
Rollback
Tran
--
Transaction Restoration
Close
Cur_1
--
Close and release a cur
Lock a table of a databaseSELECT * from table with (HOLDLOCK)Note: The difference between a table that locks a databaseSELECT * from table with (HOLDLOCK)Other transactions can read the table, but cannot update the deleteSELECT * from table with (TABLOCKX)Other transactions cannot read tables, updates, and deletesFeature description for "Lock options" in SELECT statementsSQL Server provides a powerful and complete locking mechanism to help achieve the
END
GO
BEGIN TRY
SELECT GETDATE ()
SELECT 1/0--evergreen divide by zero example!
END TRY
BEGIN CATCH
SELECT ' There is an error! ' + error_message ()
RETURN
END CATCH;
2. The function table that obtains the error message:The following system functions are valid in the CATCH block. Can be used to get more error messages:
function
Description
Error_number ()
Returns the error number of the e
, status 0, procedure TT1, 17th rowsThe insert statement conflicts with the check constraint "T1. This conflict occurs in the Database "test", table "DBO. Salary", column 'salary '.The statement has been terminated.
(One row is affected)
No output in the result 111 indicates that the stored procedure is not executed.
Test environment: SQL Server 2005 Express
This is another example:
1.
The garden has a very good article about SQL Server transaction isolation, feeling a lot of the introduction from the concept, for those beginners, see the touch of understanding is profound, so no longer repeat, the emphasis is on the example demonstration above.
The first explanation is what transaction isolation is
On the weekend, I helped a buddy find a tool to view SQL Server redo logs, which is quite good. I do not dare to enjoy it exclusively. I recommend it to you.
I have successfully installed SQL server on the machine and can connect to use it, but cannot connect to a remote database. The error is: a proxy. cpp file is mi
Tags: blog http io strong SP on log CTIGet ready:CREATE TABLE Nums (X int);Purpose: Inserts only one row into the table.--------------------------------------------------------------------------------------------------------------- ---------------------- BEGIN TRANSACTION Tran_a-it is best to define a name for the transaction.Insert into Nums (X) VALUES (9); Save Tr
second connection
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDPrint 'dirty read'Select * from table1If @ rowcount> 0BeginWaitfor delay '00: 00: 10'Print 'no-repetition read'Select * from table1End
Result of the second connection
Dirty read
A
B
C
A1
B1
C1
A2
B2
C
A3
B3
C
'No repeated read'
A
B
C
A1
B1
C1
A2
B2
C2
A3
B3
C3
SQL ServerMedium DatabaseTransaction ProcessingIs quite useful, given that many SQL beginners write Transaction ProcessingCodeVulnerabilities often exist. This article introduces three different methods to illustrate howStored ProcedureWrite the correct code in transaction processing. Hope to help you.
When writing
Transaction Log
Transaction Log Transaction logs) is a very important but often ignored part of the database structure. Since it is not as active as the schema in the database, few people are concerned about transaction logs.
The database image solution has two operating modes. One is "high security mode", which supports synchronization operations. In high security mode, when the session starts, the backup storage synchronizes the backup storage with the master database as soon as possible. Once the database is synchronized, the transaction will be submitted by both partners, this will prolong the transaction latency. The second
databases.-- The Instance name is RemoteServer. The local and remote databases submit or roll back the transaction at the same time.-- Note that four naming rules are used for executing distributed queries or calling stored procedures.
-- Prerequisite: the MSDTC Service on the local machine and the MSDTC Service on the remote machine must be enabled.-- The local machine and remote machine can ping each other-- Database ports can be telnet to each oth
SQL Server lock mechanism (I) Overview (lock type and scope) SQL Server lock mechanism (ii) Overview (Lock compatibility and lockable resources) this article introduces the SQL Server lock mechanism (iii) Overview (lock and
parts of log shipping;master.dbo.sp_add_log_shipping_primary_database Sets the log shipping configuration for the primary database and sets the log shipping backup job.Msdb.dbo.sp_add_schedule Set a schedule for log shipping, or set a schedule for the copy job, or set a schedule for the restore job.msdb.dbo.sp_attach_
Tags: DBCC article BSP color size ASE file detail supportSQL Server log file too large log file cleanup method, the network provides a lot of separate database--〉 delete log files-〉 Additional database method, this method is too risky, the process is relatively long, and sometimes there will be the phenomenon of separa
Too many VLFsSQLServer database engines divide each physical log file into multiple virtual log files, so that the log management system can easily track which parts can be reused. The transaction log file determines the number of VLFs generated based on the following formul
The Enterprise Edition cannot be installed under XP, So download a Personal Edition
After the installation is complete, the system prompts "MSSQL installation prompt reference Server Error Log and C:/winnt/sqlstp. log for more information"
Solution:
First, delete the Microsoft SQL
1. It is best to have only one transaction for a stored procedure; multiple transactions consume both resources and are prone to errors;
2. When creating a transaction and ending a transaction, you 'd better have the following judgment:Code
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->IF @ TRANCOUNT = 0
BEGIN
to specify the name of the maintenance plan. Finish to start the log shipping creation.
Monitor
1. After the log shipping is created, the information associated with log shipping is stored in the 7 tables in msdb:
Log_shipping_plans
Log_shipping_plan_databases
Log_shipping_databases
Log_shipping_plan_history
Log_shipping_monitor
Log_shipping_primaries
Log
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.