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