The examples in this article describe SQL Server triggers and transaction usages. Share to everyone for your reference, specific as follows:
Add and remove triggers
Alter TRIGGER TRI_TC on T_c to
Insert,delete
as
begin
set XACT_ABORT on
declare @INSERTCOUNT int;
Update triggers and transactions
Transactions are primarily used for data protect
, PersonName)Values ('1', 'name1 ')Insert Into Person (PersonId, PersonName)Values ('3', 'name3 ')Commit TransAction/*Select values include '1', 'name1', and '3', 'name3 ',This indicates that only the error in the second sentence has been canceled.*/
Method 1 for all rollback: Open XACT_ABORT
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->Use TestDB
SET XACT_ABORT ON -- open
Begin
')
GO 2 rollback Cases --the simplest rollback
--The following statements can be executed separately, one line at a time
BEGIN TRAN --open transaction, set transaction start point
/*The command was successfully completed. */
SELECT * fromscore/*(0 rows affected) Description: Because there is no data in the table, the query returns the number of bars to 0.*/
INSERT intoScoreVALUES(101, -)--Insert da
You often need to modify the data in the database through the stored procedure. You need to configure distributed transactions on the source and target database servers. The configuration process is cumbersome, distributed transactions are caused by both the operating system and SQL Server. After reading the article "SQL Serv
The batch log recovery mode of the SQL Server recovery model.
Do you want to know why the transaction log file is getting bigger and bigger? Transaction logs are sometimes larger than your actual database files, especially in the
The transaction log (Transaction logs) is a very important but often overlooked part of the database structure. Because it is not as active as the schema in the database, few people are concerned about the transaction log.
The transacti
Zheng Zuo 2006-6-26
During the BizTalk project, BizTalk Server and SQL
The server is not on the same computer, and the SQL adapter is used to send data prompting the error "new transactions cannot be registered to the specified transaction processor". The same problem occurs
Label:SQL Server transaction log unexpectedly increases or fills up the processing methodTransaction log files transaction log file is a file that is used to record database updates, with an extension of LDF.In
rolled back'
ENDCatch Test commit and rollback transactions are OK. 3. Auxiliary statements -- -Delete table, restore self-increment starting from 1 truncate table testtable -- -display insert self-increment set identity_insert testtable on insert into testtable (testid,testname) values (32 , " 5 " ) identity_insert testtable off Attention: 1.set Identity_insert is only valid for the current session. 2.Set identity_insert table name on set, you must display the specified ID
Begin:Start transaction; # Be sure to have this '; ' number.Attention:MYSQL uses snapshot isolation, which means that a connection can be queried when it is modified.Example:CREATE TABLE T1 (X int);Insert into T1 (X) values (100);Connect A,Start transaction;Update T1Set X = 200;Connection B,Select X from T1; ------Return 100------------------------------------------------------------------------------------
Tags: run backup file management clears CTI Trunc set DBCC SQL2008 's shrink log due to SQL2008 's optimization of file and log management, the following statements can be run in SQL2005 but have been canceled in SQL2008: (SQL2005) Backuplog dnname withno_logGo
Dump TransactionDnname withno_logGo
UseDnnameDBCCShrinkfile (2)
Go
--------------------------------------------------------------
(SQL2008): In the
Over time, you will find that the log files for the database will be up to 20G or more, and you will need the following methods.--first change the recovery model of the database to SimpleALTER DATABASE [Database] SETRECOVERY Simple;GO--to reduce the log file to 1M, the logical name can be obtained by sp_helpfileDBCCShrinkfile ([Database log name],1); GO--Resettin
SQL Server's TRUNCATE transaction rollback operation method, servertruncate
We generally think that TRUNCATE is an operation that cannot be rolled back. It will delete all data in the table and reset the Identity column.
If you perform the TRUNCATE operation in the transaction, you can roll back. Otherwise, it will not recover data from the
transaction log, instead of backing up (copying) the log to the backup device. Because the logs are not copied, you do not need to specify the backup device when using truncate_only. For example, the syntax for using the truncate_only option to back up the transaction logs of the primary database is as follows:Backup
Delete a message will cascade delete response information, then we need to use the transaction, the following SQL
Copy Code code as follows:
ALTER PROCEDURE [dbo]. [Proc_tb_leaveword_delete]
(
@leavewordID INT,
@record TINYINT OUTPUT
)
As
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE from Tb_leavewordid WHERE leavewordid= @leavewordID
DELETE from
Stored Procedure format:CREATE PROCEDURE yourprocedure asbegin SET NOCOUNT on; BEGIN TRY---------------------start catching exception BEIN TRAN------------------start transaction UPDATE A SET a.names= B.names from T1 as A INNER joins T2 as B on a.id =b.id UPDATE A SET a.names= B.names from T1 as A INNER joins T2 as B on a.test =b.test COMMIT TRAN-------COMMIT TRANSACTION END TRY-----------End catch Exceptio
504K.
You can also do this by using a command:
Use master;
exec sp_detach_db @dbname = ' TestDB ';
exec sp_attach_single_file_db @dbname = ' TestDB ', @physname = ' D:program filesmicrosoft SQL ServerMSSQL10.SQL2008MSSQLDATATestDB.mdf '
Second, empty the log
This command is supported in SQL Server 2005 and 2000,
.
there is a SQL Server Agent service in SQL Server that has a " job function ", much like a timer trigger ,
using a " job " to execute a specific T-SQL statement or process at a specific time is an efficient and effective method .
2.
Generate forecast Control Table
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.