SQL Server, a few small common sense (personal collation)

Source: Internet
Author: User
Tags insert
server|sqlserver| programming
1. Remove the data you just inserted (delete) Select field name from INSERTED (DELETED)
2, for update is actually first delete and then insert so if you want to get update before and after the data value, you should first remove from the deleted, and then remove from the inserted;
3, IF Update (column name) to determine the update or insert the value of which field;
4, @ @ROWCOUNT can determine the last line of query operations to get the number of columns;
5. Assign value to variable with set @ZQB = 13;
6. See if there is a qualifying record if EXISTS (SELECT name from sysobjects WHERE name = ' Reminder ' and type = ' TR ');
7. Define the cursor as follows:
DECLARE C1 CURSOR for
SELECT emp_mgr.emp
From Emp_mgr, inserted
WHERE emp_mgr.emp = inserted.mgr

OPEN C1
Fetch NEXT from C1 into @e--remove data from the cursor
While @ @fetch_status = 0--Determines whether the last
BEGIN
UPDATE Emp_mgr
SET Emp_mgr. NoOfReports = Emp_mgr. NoOfReports + 1--ADD 1 for newly
WHERE emp_mgr.emp = @e-Added employee.

FETCH NEXT from C1 into @e
End
Close C1
DEALLOCATE c1--Delete Cursor reference


Related Article

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.