SQL does not commonly use function summary and transactions, add or delete triggers
Delete duplicate rows in distinct
Declare @ x declare a variable
Convert (varchar (20), tscore. tenglish) type conversion
Cast (xx as varchar (10) type conversion
Www.jb51.net
========================================================== ====================
Situation
Case
When xxx then xx
When xxxx then xxxxx
Else
End
========================================================== ====================
While xxx
Begin
Xxxxxx
End
Www.jb51.net
Transactions
========================================================== ==============
Begin tran
Declare @ sum int = 0
Update bank set balance = balance-1000 where cid = '000000'
Set @ sum = @ sum + @ error
Update bank set balance = balance + 1000 where cid = '000000'
Set @ sum = @ sum + @ error
If @ sum <> 0
Begin
Rollback
Print 'rollback! '
End
Else
Begin
-- Submit a transaction
Commit tran
Print 'submitted! '
End
========================================================== ==============
Begin tran www.jb51.net
Begin try
Declare @ sum int = 0
Update bank set balance = balance-900 where cid = '000000'
Set @ sum = @ sum + @ error
Update bank set balance = balance + 900 where cid = '000000'
Set @ sum = @ sum + @ error
Commit
End try
Begin catch
Rollback
End catch
========================================================== ==================
Declare @ halfCount int = ceiling (@ count/2.0) Up
Trigger added
========================================================== =
Create trigger tri_TblClass_insert_after
On TblClass after insert
As
Begin
Declare @ id int
Declare @ name varchar (50)
Declare @ desc varchar (50)
Select @ id = tclassId, @ name = tclassname, @ desc = tclassdesc from inserted
Print @ id
Print @ name
Print @ desc
End www.jb51.net
========================================================== =
Trigger upon deletion
Create trigger tri_TblClass_delete_after
On TblClass instead of delete
As
Begin
Insert into tblclassbk
Select * from deleted
End
==========================================================
Author xhccom