SQL server用到的SQL语句备份下
这是触发器用于关联条件的
-------------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语句备份下的更多相关文章
- SQL Server中常用的SQL语句(转):
SQL Server中常用的SQL语句 转自:http://www.cnblogs.com/rainman/archive/2013/05/04/3060428.html 1.概述 名词 笛卡尔积.主 ...
- 关于SQL Server 2005 的自动远程数据库备份
原文:(原创)关于SQL Server 2005 的自动远程数据库备份 由于项目需要,需要对目标服务器上的数据库每天进行备份并转移,查阅网上的一些帮助,结合自己的实际需要,写了这篇文章,希望对有同样需 ...
- 【转】SQL Server 运行状况监控SQL语句
SQL Server 运行状况监控SQL语句 Microsoft SQL Server 2005 提供了一些工具来监控数据库.方法之一是动态管理视图.动态管理视图 (DMV) 和动态管理函数 (D ...
- 使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)
使用SQL Server 2008的事务日志传送功能备份数据库(logshiping) 使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)
- 监控SQL Server正在执行的SQL语句和死锁情况
原文:监控SQL Server正在执行的SQL语句和死锁情况 SELECT [Individual Query] = SUBSTRING(qt.TEXT, er.statement_start_off ...
- SQL Server 创建唯一约束sql语句
SQL Server 创建唯一约束sql语句 语句示例: 在创建表是时同时创建, 创建id,name,sex三个字段的唯一索引 create table t1( id int primary ...
- 【SQL Server DBA】日常巡检语句3:特定监控(阻塞、top语句、索引、作业)
原文:[SQL Server DBA]日常巡检语句3:特定监控(阻塞.top语句.索引.作业) 1.查询阻塞信息.锁定了哪些资源 --1.查看阻塞信息 select spid,loginame,wai ...
- 【SQL Server学习笔记】Delete 语句、Output 子句、Merge语句
原文:[SQL Server学习笔记]Delete 语句.Output 子句.Merge语句 DELETE语句 --建表 select * into distribution from sys.obj ...
- sql server 查询log日志 sql语句
xp_readerrorlog 一共有7个参数: 1. 存档编号 2. 日志类型(1为SQL Server日志,2为SQL Agent日志) 3. 查询包含的字符串 4. 查询包含的字符串 5. Lo ...
- 第三篇——第二部分——第五文 配置SQL Server镜像——域环境SQL Server镜像日常维护
本文接上面两篇搭建镜像的文章: 第三篇--第二部分--第三文 配置SQL Server镜像--域环境:http://blog.csdn.net/dba_huangzj/article/details/ ...
随机推荐
- 第一章 React新的前端思维方式
---恢复内容开始--- 第一章 React新的前端思维方式 1.1 初始化一个React项目 1.安装create-react-app npm install --global create-rea ...
- java基础学习日志--异常案例
package test7; public class InvalidScroreException extends Exception { public InvalidScroreException ...
- [Luogu] P3225 [HNOI2012]矿场搭建
题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一个挖煤点坍塌之 ...
- ubuntu 通过ppa源安装mysql5.6
添加mysql5.6的源 sudo add-apt-repository -y ppa:ondrej/mysql-5.6 更新源 sudo apt-get update 安装mysql5.6 sudo ...
- Win2008 Server下配置安装IIS
最近又买了台服务器,接下来就是配置环境啦. 接下来接记录一下IIS的配置过程. 首先找到服务器管理器 打开后找到角色,点击添加角色 处理添加角色向导 勾选Web服务器(IIS) 点击添加必要功能 然后 ...
- 利用python去调用shell命令时候的踩到的坑
shell中 True的返回值是0 False的返回值是1 Python中 True的返回值是1 False的返回值是0
- 51NOD 1287 加农炮(不水的线段树)
>>点击进入原题测试<< Input示例 Output示例 思路:刚开始以为结点存最大值就行了,然后大于左子树的最大值就能进入右子树:然后发现样例都过不了:后面发现,并不是这个 ...
- getContextPath和getRealPath的区别-----其实主要区别就是相对路径和绝对路径
getContextPath和getRealPath的区别 其实主要区别就是相对路径和绝对路径 https://blog.csdn.net/zsmj_2011/article/details/4121 ...
- noip模拟赛 排列
[问题描述] 给出一个随机的排列,请你计算最大值减最小值的差小于等于0~n-1的区间分别有多少个. 输入格式 输入文件名为sum.in. 第一行一个数T(<=10),表示数据组数 对于每一组数据 ...
- node.js 利用流实现读写同步,边读边写
//10个数 10个字节,每次读4b,写1b let fs=require("fs"); function pipe(source,target) { //先创建可读流,再创建可写 ...