Home > Database > Mysql Tutorial > body text

SQL Server 利用触发器对多表视图进行更新

WBOY
Release: 2016-06-07 17:44:30
Original
1156 people have browsed it

插入【ZHONGHE_TAB】中的数据 1 USE [SQL- LI] 2 -- 声明3个变量分别用来接收【平均分】,【总分】,【姓名】,和一个控制循环的条件变量@I_WHILE_XUEHAO 3 DECLARE @I_WHILE_XUEHAO INT,@ZONGFEN DECIMAL( 4 , 1 ),@AVGFEN DECIMAL( 3 , 1 ),@XINGMING NVAR

插入【ZHONGHE_TAB】中的数据

1 USE [SQL-LI] 2 --声明3个变量分别用来接收【平均分】,【总分】,【姓名】,和一个控制循环的条件变量@I_WHILE_XUEHAO 3 DECLARE @I_WHILE_XUEHAO INT,@ZONGFEN DECIMAL(4,1),@AVGFEN DECIMAL(3,1),@XINGMING NVARCHAR(10); 4 SELECT @I_WHILE_XUEHAO =6080; 5 --使这个变量【@I_WHILE_XUEHAO】的值指定在【学号】字段上 6 WHILE(@I_WHILE_XUEHAO >=6080 AND @I_WHILE_XUEHAO 6085) 7 BEGIN 8 --求取【平均分】,香港服务器,香港服务器,香港空间,【总分】,【姓名】并存在声明的变量中 9 SELECT @ZONGFEN =(F.语文 +F.数学 +F.英语 ),@AVGFEN =(F.语文 +F.数学 +F.英语 )/3,@XINGMING =X.姓名 10 FROM[DBO].XINXIN_TAB AS X INNER JOIN [DBO].FENSHU_TAB AS F ON X.学号 =F.学号 11 WHERE X.学号 =@I_WHILE_XUEHAO --与【学号同步】 12 --将其变量的数据插入到【ZHONGHE_TAB】的对应字段上 13 INSERT INTO [DBO].ZHONGHE_TAB ([姓名] ,[学号] ,[平均分] ,[总分] ) 14 VALUES(@XINGMING ,@I_WHILE_XUEHAO ,@AVGFEN ,@ZONGFEN ) 15 SELECT @I_WHILE_XUEHAO +=1; --与【学号同步】 16 END 17 GO

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!