SQL Service Database Basic operation view trigger cursor stored procedure

Source: Internet
Author: User
Tags terminates

Use NewTest1---Declaration view---CREATE VIEW newviewteasselect studentinfo.name as name, studentinfo.sex as gender, course.name as course from St Udentinfo join Course on studentinfo.cid= course.id---Call view select * FROM newviewte---declaration trigger---CREATE TRIGGER newtrion Class Infofor insertas print ' data insert test ' Gocreate trigger newtri1on classinfofor deleteas print ' data delete test ' Goinsert into ClassInfo Values (' Test name ', ' Test teacher name ') Delete from ClassInfo where Id=7create trigger newtri11on coursefor insertas print ' Data insert test ' Gocreate trigger newtri111on coursefor deleteas print ' data delete test ' GO---declaration cursor---Declare newdeclare cursorforselect * from Stud Entinfo where cid= ' 1 '---cursor opens cursor using------open newdeclare---Read data fetch fetching FETCH NEXT from Newdeclareselect * from Studentinfo where cid= ' 1 '---closed cursor close newdeclare---Delete cursor deallocate release deallocate newdeclare---Create stored procedure---creation proc newproc@cname Nv Archar, @TeacheName Nvarchar (), @Name Nvarchar () Asbegin begin try begin tran insert into Course values (@c Name) insert INTO ClassInfo valuEs (@Name, @TeacheName) Commit Tran End Try begin catch---If an exception is caught---the operation terminates to the original if @ @TRANCOUNT >0---in sqlser In Ver, the hierarchy of nested transactions is reflected by the @ @TranCount global variable---Then the operation terminates back to the initial begin rollback end END catchendexec newproc @Cname = ' Test course name ', @TeacheName = ' Test teacher name ', @Name = ' Test name '

  

SQL Service Database Basic operation view trigger cursor stored procedure

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.