SQL Server uses triggers to update multi-table views

Source: Internet
Author: User
Insert data 1USE [SQL-LI] 2 -- declare three variables are used to receive [average score], [total score], [name ], and the condition variable @ I _WHILE_XUEHAO3DECLARE @ I _WHILE_XUEHAOINT, @ ZONGFENDECIMAL (), @ AVGFENDECIMAL (), @ XINGMINGNVAR

Insert data 1 USE [SQL-LI] 2 in [ZHONGHE_TAB] -- declare three variables to receive the [average score], [total score], [name ], and the condition variable @ I _WHILE_XUEHAO 3 DECLARE @ I _WHILE_XUEHAO INT, @ ZONGFEN DECIMAL (4, 1), @ AVGFEN DECIMAL (3, 1), @ XINGMING NVAR

Insert data in [ZHONGHE_TAB]

1 USE [SQL-LI] 2 -- declare three variables are used to receive [average score], [total score], [name ], and the condition variable @ I _WHILE_XUEHAO 3 DECLARE @ I _WHILE_XUEHAO INT, @ ZONGFEN DECIMAL (), @ AVGFEN DECIMAL (), @ XINGMING NVARCHAR (10 ); 4 SELECT @ users = 6080; 5 -- set the value of this variable [@ I _WHILE_XUEHAO] to 6 WHILE (@ I _WHILE_XUEHAO> = 6080 AND @ I _WHILE_XUEHAO <6085) 7 BEGIN 8 -- calculate [average score], Hong Kong server, Hong Kong server, Hong Kong Space, [total score], [name], and 9 SELECT @ ZONGFEN = (F. language + F. mathematics + F. english), @ AVGFEN = (F. language + F. mathematics + F. english)/3, @ XINGMING = X. NAME 10 FROM [DBO]. XINXIN_TAB as x inner join [DBO]. FENSHU_TAB as f on x. student ID = F. student ID 11 where x. student ID = @ I _WHILE_XUEHAO -- synchronize the student ID with [student ID] 12 -- INSERT the data of the variable to the corresponding field of [ZHONGHE_TAB] 13 INSERT INTO [DBO]. ZHONGHE_TAB ([name], [student ID], [average score], [total score]) 14 VALUES (@ XINGMING, @ I _WHILE_XUEHAO, @ AVGFEN, @ ZONGFEN) 15 SELECT @ I _WHILE_XUEHAO + = 1; -- synchronize with [student ID] 16 END17 GO

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.