以前都是也得mysql,现在写sqlserver的触发器,感觉改动还是蛮大的 1.定义变量 #在mysql中变量直接这么定义就可以了SET @VALUE = 111;#在sql server中declare @count int;#并赋值set @count =0;#如果是查询,必须这么些select @count = count(*) from WQ_MNI
以前都是也得mysql,现在写sqlserver的触发器,感觉改动还是蛮大的
1.定义变量
#在mysql中变量直接这么定义就可以了 SET @VALUE = "111"; #在sql server中 declare @count int; #并赋值 set @count =0; #如果是查询,必须这么些 select @count = count(*) from WQ_MNINF_D_REAL where STCD=@stcd;
2.判断
在mysql中,if判断的格式
if 条件 then 语句 end if;
而在sql server中,if判断的格式
if(条件) begin 语句 end;
例子
#mysql IF @VALUE4=1 THEN INSERT INTO t_sca_history_data (METER_CODE,PARAM_CODE,DATA_VALUE,V_VALUE,DATE_TIME) VALUES (NEW.METER_CODE,NEW.PARAM_CODE,NEW.DATA_VALUE,NEW.V_VALUE,NEW.DATE_TIME); END IF; sql server if(@count=0) begin insert into WQ_MNINF_D_REAL select STCD,TYPE,UPPERVALUE,LOWERVALUE,TM,NT,@smid,@stnm,@prjcd,@pipcd from inserted; end
3.触发器的new
在mysql中,用new.NAME 可以得到触发器触发插入的值,而sql server不是这样的,sql server是把处罚的数据放在一个临时表中,所以它的操作是这样的
#inserted代表插入数据的那张临时表,同时还有deleted 这张用作删除数据的临时表 select STCD from inserted #若只是把插入的数据插入另一张表,语句如下 insert into WQ_WWFINF_D_REAL select PRJCD,TM,INFL,SWWL,CWWL,OTPS,OTF,QOEC,PSPPS,NT FROM inserted; #如果还有加点别的数据,可以这么做 insert into WQ_MNINF_D_REAL select STCD,TYPE,UPPERVALUE,LOWERVALUE,TM,NT,@smid,@stnm,@prjcd,@pipcd from inserted;
4.我做的触发器的代码,改触发器的作用是把原始数据表的数据插入到实时数据表中,如果实时表没有该数据,就插入,如果有,就删除再插入
BEGIN declare @stcd varchar(30); declare @count int; declare @smid int; declare @stnm varchar(30); declare @prjcd varchar(30); declare @pipcd varchar(30); select @stcd = STCD from inserted; select @count = count(*) from WQ_MNINF_D_REAL where STCD=@stcd; select @smid = SMID from WQ_WQSINF_B where STCD=@stcd; select @stnm = STNM from WQ_WQSINF_B where STCD=@stcd; select @prjcd = PRJCD from WQ_WQSINF_B where STCD=@stcd; select @pipcd = PIPCD from WQ_WQSINF_B where STCD=@stcd; if(@count=0) begin insert into WQ_MNINF_D_REAL select STCD,TYPE,UPPERVALUE,LOWERVALUE,TM,NT,@smid,@stnm,@prjcd,@pipcd from inserted; end else begin delete WQ_MNINF_D_REAL where STCD=@stcd; insert into WQ_MNINF_D_REAL select STCD,TYPE,UPPERVALUE,LOWERVALUE,TM,NT,@smid,@stnm,@prjcd,@pipcd from inserted; end END
这篇博文给我作用挺大的,一并贴出
http://blog.csdn.net/chenbin520/article/details/6026686

本篇文章给大家带来了关于SQL的相关知识,其中主要介绍了SQL Server使用CROSS APPLY与OUTER APPLY实现连接查询的方法,文中通过示例代码介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于SQL server的相关知识,其中主要介绍了SQL SERVER没有自带的解析json函数,需要自建一个函数(表值函数),下面介绍关于SQL Server解析/操作Json格式字段数据的相关资料,希望对大家有帮助。

如何优化sql中的orderBy语句?下面本篇文章给大家介绍一下优化sql中orderBy语句的方法,具有很好的参考价值,希望对大家有所帮助。

monacoeditor创建//创建和设置值if(!this.monacoEditor){this.monacoEditor=monaco.editor.create(this._node,{value:value||code,language:language,...options});this.monacoEditor.onDidChangeModelContent(e=>{constvalue=this.monacoEditor.getValue();//使value和其值保持一致i

本篇文章给大家带来了关于SQL server的相关知识,开窗函数也叫分析函数有两类,一类是聚合开窗函数,一类是排序开窗函数,下面这篇文章主要给大家介绍了关于SQL中开窗函数的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下。

0x01前言概述小编又在MySQL中发现了一个Double型数据溢出。当我们拿到MySQL里的函数时,小编比较感兴趣的是其中的数学函数,它们也应该包含一些数据类型来保存数值。所以小编就跑去测试看哪些函数会出现溢出错误。然后小编发现,当传递一个大于709的值时,函数exp()就会引起一个溢出错误。mysql>selectexp(709);+-----------------------+|exp(709)|+-----------------------+|8.218407461554972

当某些sql因为不知名原因堵塞时,为了不影响后台服务运行,想要给sql增加执行时间限制,超时后就抛异常,保证后台线程不会因为sql堵塞而堵塞。一、yml全局配置单数据源可以,多数据源时会失效二、java配置类配置成功抛出超时异常。importcom.alibaba.druid.pool.DruidDataSource;importcom.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;importorg.apache.

monacoeditor创建//创建和设置值if(!this.monacoEditor){this.monacoEditor=monaco.editor.create(this._node,{value:value||code,language:language,...options});this.monacoEditor.onDidChangeModelContent(e=>{constvalue=this.monacoEditor.getValue();//使value和其值保持一致i


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools