这是触发器用于关联条件的

-------------1--------------

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER trigger [Collection_GasInsert]
on [dbo].[Collection_Gas]
FOR INSERT
AS
declare @GasName varchar(10)
set @GasName=''
declare @GasPpb decimal(18, 0)
set @GasPpb=0

declare @AlarmName varchar(10)
set @AlarmName=''
declare @Condition decimal(18,0)
set @Condition=0

begin
select @GasName=GasName,@GasPpb=GasPpb from Collection_Gas where ID in (select Top 1 ID from Collection_Gas order by CollectTime desc)
select top 1 @AlarmName=AlarmName,@Condition=Condition from AlarmInfoSet
if (@GasPpb > @Condition)
insert into AlarmInfoList(AlarmName,GasName,AlarmContext) VALUES (@GasPpb,@GasName,@GasName);
print 'Collection_Gas 下 AlarmInfoList表更新了1条数据'
end

----------触发器

CREATE TRIGGER BaseInfoUpdate
ON BaseInfo
for update
AS
print 'BaseInfoUpdate表更新了'

---

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [BaseInfoUpdate]
ON [dbo].[BaseInfo]
for update
AS
print 'BaseInfoUpdate表更新了1条数据'

------------1结尾------

插入语句 简单备份下 -----2

use GHGD;

insert into Collection_Gas (GasName,GasPpb,GasMaxPpb,GasR2,CollectAddress,CollectTime,Operator,Isalarm)
values('NA1','141','19','19','19','1989/9/9','19','0');

SELECT * FROM Collection_Gas;
SELECT * FROM AlarmInfoList;

update BaseInfo set Operatorer = '陈玲玲1',Address='香山',CollectionTime='15' where id = 1;

use ghgd;
insert into Collection_Gas (GasName,GasPpb,GasMaxPpb,GasR2,CollectAddress,CollectTime,Operator,Isalarm)
values('NA1','11','19','19','19','2909/9/09 00:01:00','19','0');

-----------2结尾----

更新的存储过程------------3

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER procedure [dbo].[UpdateCheckBoxFrmSetControl_AndnalyseINFO]
(@ID int,@Unit int,@Unitratio int,@Algorithm int,@Lenth int,@SetInitialData bit,@Setdensity bit,@Transit bit)
as
begin
update Andnalyse set Unit=@Unit,Unitratio=@Unitratio,Algorithm=@Algorithm,
Lenth=@Lenth,SetInitialData=@SetInitialData,Setdensity=@Setdensity,Transit=@Transit
where ID=@ID
end

-----

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

create procedure [dbo].[FrmSetting_BaseInfo_UpdateInfo]
(@caoZuoZhe varchar(50),@jianCeDiDian varchar(50),@caiJiShiJian varchar(50),@idfst int)
as
begin
update BaseInfo set Operatorer=@caoZuoZhe,Address=@jianCeDiDian,CollectionTime=@caiJiShiJian where ID=@idfst
end

---------------

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER procedure [dbo].[Get_Frmsetting_DicInfo]
(@str varchar(50))
as
begin
select Name from Dic where Type = @str
end

--------------------------------3 结束------------------

0------------4 重点-----------------查询出气体名称 、时间分组的 再通过关联关系 查询出所有数据------------

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER procedure [dbo].[FrmCount_Collection_Gas_GetInfoDescTime]
as
begin

select distinct a.GasName, a.CollectTime,a.GasPpb,a.GasMaxPpb,a.GasR2,a.Operator from Collection_Gas a,
(select distinct GasName,max(CollectTime) CollectTime from Collection_Gas group by GasName) b where a. GasName = b. GasName and a.CollectTime = b.CollectTime

end

----------------------4 结束-----------------------

-----------------------------5---------------这个功能代码是:创建触发器 通过触发器的关联条件插入到另一行

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER trigger [AlarmInfoListInsert]
on [dbo].[AlarmInfoList]
FOR INSERT
AS
declare @GasName varchar(10)
set @GasName=''
declare @GasPpb decimal(18, 0)
set @GasPpb=0

declare @AlarmName varchar(10)
set @AlarmName=''
declare @Condition decimal(18,0)
set @Condition=0

begin
select @GasName=GasName,@GasPpb=GasPpb from Collection_Gas where ID in (select Top 1 ID from Collection_Gas order by CollectTime desc)
select top 1 @AlarmName=AlarmName,@Condition=Condition from AlarmInfoSet
--if(@GasPpb>@Condition)
insert into AlarmInfoList(AlarmName,GasName,AlarmContext) VALUES (@AlarmName,@GasName,@GasName);

end
print 'AlarmInfoList表更新了1条数据'

-----------------------------------------------

SQL server用到的SQL语句备份下的更多相关文章

  1. SQL Server中常用的SQL语句(转):

    SQL Server中常用的SQL语句 转自:http://www.cnblogs.com/rainman/archive/2013/05/04/3060428.html 1.概述 名词 笛卡尔积.主 ...

  2. 关于SQL Server 2005 的自动远程数据库备份

    原文:(原创)关于SQL Server 2005 的自动远程数据库备份 由于项目需要,需要对目标服务器上的数据库每天进行备份并转移,查阅网上的一些帮助,结合自己的实际需要,写了这篇文章,希望对有同样需 ...

  3. 【转】SQL Server 运行状况监控SQL语句

    SQL Server 运行状况监控SQL语句   Microsoft SQL Server 2005 提供了一些工具来监控数据库.方法之一是动态管理视图.动态管理视图 (DMV) 和动态管理函数 (D ...

  4. 使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)

    使用SQL Server 2008的事务日志传送功能备份数据库(logshiping) 使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)

  5. 监控SQL Server正在执行的SQL语句和死锁情况

    原文:监控SQL Server正在执行的SQL语句和死锁情况 SELECT [Individual Query] = SUBSTRING(qt.TEXT, er.statement_start_off ...

  6. SQL Server 创建唯一约束sql语句

    SQL Server 创建唯一约束sql语句   语句示例:   在创建表是时同时创建, 创建id,name,sex三个字段的唯一索引 create table t1( id int primary ...

  7. 【SQL Server DBA】日常巡检语句3:特定监控(阻塞、top语句、索引、作业)

    原文:[SQL Server DBA]日常巡检语句3:特定监控(阻塞.top语句.索引.作业) 1.查询阻塞信息.锁定了哪些资源 --1.查看阻塞信息 select spid,loginame,wai ...

  8. 【SQL Server学习笔记】Delete 语句、Output 子句、Merge语句

    原文:[SQL Server学习笔记]Delete 语句.Output 子句.Merge语句 DELETE语句 --建表 select * into distribution from sys.obj ...

  9. sql server 查询log日志 sql语句

    xp_readerrorlog 一共有7个参数: 1. 存档编号 2. 日志类型(1为SQL Server日志,2为SQL Agent日志) 3. 查询包含的字符串 4. 查询包含的字符串 5. Lo ...

  10. 第三篇——第二部分——第五文 配置SQL Server镜像——域环境SQL Server镜像日常维护

    本文接上面两篇搭建镜像的文章: 第三篇--第二部分--第三文 配置SQL Server镜像--域环境:http://blog.csdn.net/dba_huangzj/article/details/ ...

随机推荐

  1. 05Servlet example

    dgdfgdfggggggg Servlet 表单数据 在客户端,GET通过URL提交数据,数据在URL中可见:POST把数据放在form的数据体内提交.GET提交的数据最多只有1024字节:POST ...

  2. Python isalpha() 方法检测字符串是否只由字母组成。

    Python isalpha() 方法检测字符串是否只由字母组成.

  3. 动态生成java、动态编译、动态加载

    我曾经见过一个“规则引擎”,是在应用系统web界面直接编写java代码,然后保存后,规则即生效,我一直很是奇怪,这是如何实现的呢?实际这就好像jsp,被中间件动态的编译成java文件,有被动态的编译成 ...

  4. angular5中的自定义指令(属性指令)

    属性型指令用于改变一个 DOM 元素的外观或行为. 在 Angular 中有三种类型的指令: 组件 — 拥有模板的指令 结构型指令 — 通过添加和移除 DOM 元素改变 DOM 布局的指令 属性型指令 ...

  5. 60s倒计时

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. JAVA实现创建Excel表并导出(转发)

    <span style="font-family:Verdana, Arial, Helvetica, sans-serif;line-height:25.2px;background ...

  7. 什么是restful

  8. 【Codeforces 1030D】Vasya and Triangle

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 参考这篇题解:https://blog.csdn.net/mitsuha_/article/details/82825862 为什么可以保证m ...

  9. fetch api & response header

    how to get fetch response header in js https://stackoverflow.com/questions/43344819/reading-response ...

  10. Codeforces Round #249 (Div. 2) 总结

    D.E还是很难的.....C不想多说什么... A:提意:给出每一组人的个数,以及一次车载容量,求出最少需要多少次才能载走所有的人. water: http://codeforces.com/cont ...