Update from Sync Service
This commit is contained in:
88
Docker/Docker 部署 MongoDB.md
Executable file
88
Docker/Docker 部署 MongoDB.md
Executable file
@@ -0,0 +1,88 @@
|
|||||||
|
1.镜像下载
|
||||||
|
下载 `MongoDB` 镜像命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
docker pull mongo
|
||||||
|
```
|
||||||
|
```
|
||||||
|
执行 `docker images` 查看镜像,下载成功,如下图:
|
||||||
|
|
||||||
|
2.启动 `MongoDB`
|
||||||
|
启动 `MongoDB` 命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
docker run -p 27017:27017 -v $PWD/db:/data/db -d mongo:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 命令说明:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
 -p 27017:27017 :
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 将容器的
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
27017
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 端口映射到主机的
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
27017
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 端口
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
 -v $PWD/db:/data/db :
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 将主机中当前目录下的**`db`**挂载到容器的
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
/data/db
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
**,作为**`mongo`**数据存储目录**``
|
||||||
|
启动成功,如下图:
|
||||||
|
|
||||||
|
3.测试连接 `MongoDB`
|
||||||
|
连接 `MongoDB` 命令:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
docker run -it mongo:latest mongo --host 172.17.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 命令说明:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|

|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
## 使用**`mongo`**镜像执行**`mongo` **命令连接到刚启动的容器**`,`**主机**`IP`**为
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
172.17.0.1
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
提示信息 `It looks like you are trying to access MongoDB over HTTP on the native driver port.` ,nice,部署 `MongoD` 成功!
|
||||||
17
Docker/Docker安装redis.md
Executable file
17
Docker/Docker安装redis.md
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
**Docker安装redis**
|
||||||
|
**1.首先下载redis镜像:**
|
||||||
|
docker pull redis
|
||||||
|
**2.然后创建一个文件夹用来存放redis的配置文件、数据等(也就是所谓的挂载目录,作用就是将此目录中的文件或文件夹覆盖掉容器内部的文件或文件夹)**
|
||||||
|
**3.在上面创建的目录下使用命令启动redis容器**
|
||||||
|
docker run -d -p 6379:6379 -v $PWD/conf/redis.conf:/usr/local/etc/redis/redis.conf -v $PWD/data:/data --name docker-redis docker.io/redis redis-server /usr/local/etc/redis/redis.conf --appendonly yes
|
||||||
|
**解释一下上面命令的意义:**
|
||||||
|
-d:表示后台运行,不加-d执行上面的命令你就会看到redis启动的日志信息了
|
||||||
|
-p:表示端口映射,冒号左面的是我们的宿主机的端口,也就是我们虚拟机的端口,而右侧则表示的是mysql容器内的端口
|
||||||
|
--name:是我们给redis容器取的名字
|
||||||
|
-v:表示挂载路径,$PWD表示当前目录下,冒号左面的表示我们宿主机的挂载目录,也就是我们虚拟机所在的文件路径,冒号右边则表是的是redis容器在容器内部的路径,上面的命令我分别挂载了redis.conf(redis的配置文件),如需使用配置文件的方式启动redis,这里则需要加上,还有redis存放数据所在的目录
|
||||||
|
--appendonly yes:表示redis开启持久化策略
|
||||||
|
|
||||||
|
作者:GatHub
|
||||||
|
链接:https://www.jianshu.com/p/2f95680f21c5
|
||||||
|
来源:简书
|
||||||
|
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
|
||||||
28
Docker/INDEX_Docker.md
Executable file
28
Docker/INDEX_Docker.md
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: Docker 索引
|
||||||
|
tags:
|
||||||
|
- 索引
|
||||||
|
created: 2026-04-21
|
||||||
|
---
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
|
||||||
|
> 自动生成的索引文件
|
||||||
|
|
||||||
|
## 文件列表
|
||||||
|
|
||||||
|
| 文件名 | 大小 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| [[Docker 部署 MongoDB]] | 1KB | |
|
||||||
|
| [[Docker安装redis]] | 1KB | |
|
||||||
|
| [[Rancher_Rancher的状态存储在什么地方?]] | 619B | |
|
||||||
|
| [[Rancher_如何在同一个主机上运行Rancher-Rancher和Rancher-Rancher-Agent]] | 957B | |
|
||||||
|
| [[centos7设置docker开机自启动,并设置容器自动重启]] | 837B | |
|
||||||
|
| [[docker rm & docker rmi & docker prune 的差异]] | 196B | |
|
||||||
|
| [[docker rm & docker rmi & docker prune 的差异]] | 196B | |
|
||||||
|
| [[docker镜像清理]] | 485B | |
|
||||||
|
| [[如何批量删除Docker中已经停止的容器]] | 1KB | |
|
||||||
|
| [[安装docker-compose]] | 545B | |
|
||||||
|
|
||||||
|
---
|
||||||
|
*共 10 个文件*
|
||||||
3
Docker/Rancher_Rancher的状态存储在什么地方?.md
Executable file
3
Docker/Rancher_Rancher的状态存储在什么地方?.md
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
==单节点安装==
|
||||||
|
==在rancher/rancher容器的内置etcd中,映射与宿主机的====/var/lib/rancher====目录下。==
|
||||||
|
> 来自 <[https://docs.rancher.cn/rancher2x/faqs/important-issue.html#_11-%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84l4%E5%B1%82%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E6%9C%8D%E5%8A%A1%E5%A4%84%E4%BA%8E-%E6%8C%82%E8%B5%B7-%E7%8A%B6%E6%80%81%EF%BC%9F](https://docs.rancher.cn/rancher2x/faqs/important-issue.html#_11-%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E7%9A%84l4%E5%B1%82%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E6%9C%8D%E5%8A%A1%E5%A4%84%E4%BA%8E-%E6%8C%82%E8%B5%B7-%E7%8A%B6%E6%80%81%EF%BC%9F)>
|
||||||
7
Docker/Rancher_如何在同一个主机上运行Rancher-Rancher和Rancher-Rancher-Agent.md
Executable file
7
Docker/Rancher_如何在同一个主机上运行Rancher-Rancher和Rancher-Rancher-Agent.md
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
==.==
|
||||||
|
==在您想要使用单个节点运行Rancher并且能够将相同节点添加到集群的情况下,您必须调整为====rancher/rancher====容器映射的主机端口。==
|
||||||
|
==如果一个节点被添加到集群,它将部署使用端口80和443的ingress控制器。这与====rancher/rancher====容器默认映射的端口冲突。==
|
||||||
|
==注意不建议在生产中把Rancher/Rancher和Rancher/Rancher-Agent运行在一台主机上,但可用于开发/演示。==
|
||||||
|
==要更改主机端口映射,替换====-p 80:80 -p 443:443====为====-p 8080:80 -p 8443:443====:==
|
||||||
|
docker run -d --restart=unless-stopped \ -p 8080:80 -p 8443:443 \ -v <主机路径>:/var/lib/rancher/ \ rancher/rancher:stable (或者rancher/rancher:latest)
|
||||||
|
> 来自 <[https://docs.rancher.cn/rancher2x/faqs/important-issue.html#_4-%E6%95%B0%E6%8D%AE%E6%8C%81%E4%B9%85](https://docs.rancher.cn/rancher2x/faqs/important-issue.html#_4-%E6%95%B0%E6%8D%AE%E6%8C%81%E4%B9%85)>
|
||||||
12
Docker/centos7设置docker开机自启动,并设置容器自动重启.md
Executable file
12
Docker/centos7设置docker开机自启动,并设置容器自动重启.md
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
**1****、设置****docker****开机启动**
|
||||||
|
systemctl enable docker
|
||||||
|
**2****、设置容器自动重启**
|
||||||
|
**1****)、创建容器时设置**
|
||||||
|
|
||||||
|
docker run -d --restart=always --name 设置容器名 使用的镜像(上面命令 --name后面两个参数根据实际情况自行修改)
|
||||||
|
--restart具体参数值详细信息: no容器退出时,不重启容器; on-failure 只有在非0状态退出时才重新启动容器; always 无论退出状态是如何,都重启容器;
|
||||||
|
|
||||||
|
**2****)、修改已有容器,使用****update**
|
||||||
|
docker update --restart=always 容器ID(或者容器名)
|
||||||
|
(容器ID或者容器名根据实际情况修改)
|
||||||
|
> 来自 <[https://www.cnblogs.com/763977251-sg/p/11839918.html](https://www.cnblogs.com/763977251-sg/p/11839918.html)>
|
||||||
2
Docker/docker镜像清理.md
Executable file
2
Docker/docker镜像清理.md
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
1. **大量****镜像通过命令 docker image prune -f 清理。**
|
||||||
|
2. **通过命令 docker images | awk 'NR!=1{print $1":"$2}' | xargs docker rmi 可以批量清除无用的镜像,且不会影响使用中的镜像和基础镜像,满足笔者的需求。** > 来自 <[https://www.cnblogs.com/sqgzy/p/11864675.html](https://www.cnblogs.com/sqgzy/p/11864675.html)> > 来自 <[https://www.cnblogs.com/sqgzy/p/11864675.html](https://www.cnblogs.com/sqgzy/p/11864675.html)>
|
||||||
28
Docker/如何批量删除Docker中已经停止的容器.md
Executable file
28
Docker/如何批量删除Docker中已经停止的容器.md
Executable file
@@ -0,0 +1,28 @@
|
|||||||
|
**方法一:**
|
||||||
|
## #**==显示所有的容器,过滤出****Exited****状态的容器,取出这些容器的****ID**==,
|
||||||
|
## sudo docker ps -a|grep Exited|awk '{print $1}'
|
||||||
|
## #**==查询所有的容器,过滤出****Exited****状态的容器,列出容器****ID**==,删除这些容器
|
||||||
|
## sudo docker rm `docker ps -a|grep Exited|awk '{print $1}'`
|
||||||
|
xx
|
||||||
|
**方法二:**
|
||||||
|
## #====删除所有未运行的容器(已经运行的删除不了,未运行的就一起被删除了)
|
||||||
|
## sudo docker rm $(sudo docker ps -a -q)
|
||||||
|
|
||||||
|
**方法三:**
|
||||||
|
## #**==根据容器的状态,删除****Exited**==状态的容器
|
||||||
|
## sudo docker rm $(sudo docker ps -qf status=exited)
|
||||||
|
|
||||||
|
**方法四:**
|
||||||
|
## #Docker 1.13**==版本以后,可以使用** **docker containers prune** ==命令,删除孤立的容器。
|
||||||
|
## sudo docker container prune
|
||||||
|
|
||||||
|
~~#~~~~删除所有镜像~~
|
||||||
|
~~sudo docker rmi $(docker images -q)~~
|
||||||
|
|
||||||
|
**附图:**
|
||||||
|
## 02-====删除所有的容器,所有未运行的容器都被删除,正在运行的无法删除,达到删除不用容器的目的。
|
||||||
|
## 03-**==低于****1.13****版本的****Docker**==,可以根据容器的状态来进行删除
|
||||||
|
## 04-**==查询所有的容器,过滤出状态为****Exited**==的容器
|
||||||
|
## 05-Docker 1.13**==版本以后,开始支持****prune**==命令,快速删除已退出的容器
|
||||||
|
|
||||||
|
> 来自 <[https://blog.csdn.net/jiangeeq/article/details/79499324](https://blog.csdn.net/jiangeeq/article/details/79499324)>
|
||||||
4
Docker/安装docker-compose.md
Executable file
4
Docker/安装docker-compose.md
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
## INSTALL AS A CONTAINER
|
||||||
|
## Compose can also be run inside a container, from a small bash script wrapper. To install compose as a container run this command:
|
||||||
|
sudo curl -L --fail [https://github.com/docker/compose/releases/download/1.25.4/run.sh](https://github.com/docker/compose/releases/download/1.25.4/run.sh) -o /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-compose
|
||||||
|
> 来自 <[https://docs.docker.com/compose/install/#alternative-install-options](https://docs.docker.com/compose/install/#alternative-install-options)>
|
||||||
15
实践积累/数据库/CAP定理(CAP theorem).md
Executable file
15
实践积累/数据库/CAP定理(CAP theorem).md
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
==在计算机科学中, CAP定理(CAP theorem), 又被称作 布鲁尔定理(Brewer's theorem), 它指出对于一个分布式计算系统来说,不可能同时满足以下三点:==
|
||||||
|
|
||||||
|
- **一致性(Consistency)** ==(所有节点在同一时间具有相同的数据)==
|
||||||
|
- **可用性(Availability)** ==(保证每个请求不管成功或者失败都有响应)==
|
||||||
|
- **分隔容忍(Partition tolerance)** ==(系统中任意信息的丢失或失败不会影响系统的继续运作)==
|
||||||
|
|
||||||
|
==CAP理论的核心是:一个分布式系统不可能同时很好的满足一致性,可用性和分区容错性这三个需求,最多只能同时较好的满足两个。==
|
||||||
|
==因此,根据 CAP 原理将 NoSQL 数据库分成了满足 CA 原则、满足 CP 原则和满足 AP 原则三 大类:==
|
||||||
|
|
||||||
|
- ==CA - 单点集群,满足一致性,可用性的系统,通常在可扩展性上不太强大。==
|
||||||
|
- ==CP - 满足一致性,分区容忍性的系统,通常性能不是特别高。==
|
||||||
|
- ==AP - 满足可用性,分区容忍性的系统,通常可能对一致性要求低一些。==
|
||||||
|

|
||||||
|
> 来自 <[http://www.runoob.com/mongodb/nosql.html](http://www.runoob.com/mongodb/nosql.html)>
|
||||||
|
> 来自 <[http://www.runoob.com/mongodb/nosql.html](http://www.runoob.com/mongodb/nosql.html)>
|
||||||
15
实践积累/数据库/Cpu 占用过高.md
Executable file
15
实践积累/数据库/Cpu 占用过高.md
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
```sql
|
||||||
|
SELECT TOP 10
|
||||||
|
```
|
||||||
|
total_worker_time/execution_count AS avg_cpu_cost, plan_handle,
|
||||||
|
execution_count,
|
||||||
|
(SELECT SUBSTRING(text, statement_start_offset/2 + 1,
|
||||||
|
(CASE WHEN statement_end_offset = -1
|
||||||
|
THEN LEN(CONVERT(nvarchar(max), text)) * 2
|
||||||
|
ELSE statement_end_offset
|
||||||
|
```sql
|
||||||
|
END - statement_start_offset)/2)
|
||||||
|
FROM sys.dm_exec_sql_text(sql_handle)) AS query_text
|
||||||
|
FROM sys.dm_exec_query_stats
|
||||||
|
```
|
||||||
|
ORDER BY [avg_cpu_cost] DESC
|
||||||
132
实践积累/数据库/HiMonitor1.0 升级到1.3脚本注意事项.md
Executable file
132
实践积累/数据库/HiMonitor1.0 升级到1.3脚本注意事项.md
Executable file
@@ -0,0 +1,132 @@
|
|||||||
|
DeviceInfo 表需要新增 [HeightDeviation]列
|
||||||
|
|
||||||
|
执行脚本,以及修改对应的ProjectID
|
||||||
|
其他的
|
||||||
|
|
||||||
|
```sql
|
||||||
|
USE [HiMonitorDB]
|
||||||
|
GO
|
||||||
|
```
|
||||||
|
/****** Object: Table [dbo].[DynamicCalculationConfig] Script Date: 2018/7/5 15:04:35 ******/
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
```sql
|
||||||
|
CREATE TABLE [dbo].[DynamicCalculationConfig](
|
||||||
|
```
|
||||||
|
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||||
|
[IsUse] [int] NULL,
|
||||||
|
[SolveMode] [int] NULL,
|
||||||
|
[RobustMode] [int] NULL,
|
||||||
|
[RatioThrdDYN] [float] NULL,
|
||||||
|
[SolvingStrategy] [int] NULL,
|
||||||
|
[RelatedProject] [int] NULL,
|
||||||
|
[FilterWindowSize] [float] NULL,
|
||||||
|
[SolveStoreInterval] [float] NULL,
|
||||||
|
CONSTRAINT [PK_DynamicCalculationConfig] PRIMARY KEY CLUSTERED
|
||||||
|
(
|
||||||
|
[ID] ASC
|
||||||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
GO
|
||||||
|
/****** Object: Table [dbo].[RoutineConfig] Script Date: 2018/7/5 15:04:35 ******/
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
SET ANSI_PADDING ON
|
||||||
|
GO
|
||||||
|
```sql
|
||||||
|
CREATE TABLE [dbo].[RoutineConfig](
|
||||||
|
```
|
||||||
|
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||||
|
[RelatedProject] [int] NULL,
|
||||||
|
[ObsType] [int] NULL,
|
||||||
|
[ObsFreq] [int] NULL,
|
||||||
|
[Intervals] [float] NULL,
|
||||||
|
[EleCutOff] [float] NULL,
|
||||||
|
[ExcludeSats] [varchar](300) NULL,
|
||||||
|
[UsedSys] [varchar](300) NULL,
|
||||||
|
[IsSaveRawData] [int] NULL,
|
||||||
|
[SaveRawDataType] [int] NULL,
|
||||||
|
[SaveDataInterval] [int] NULL,
|
||||||
|
CONSTRAINT [PK_RoutineConfig] PRIMARY KEY CLUSTERED
|
||||||
|
(
|
||||||
|
[ID] ASC
|
||||||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
GO
|
||||||
|
SET ANSI_PADDING OFF
|
||||||
|
GO
|
||||||
|
/****** Object: Table [dbo].[RTKCalculationConfig] Script Date: 2018/7/5 15:04:35 ******/
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
```sql
|
||||||
|
CREATE TABLE [dbo].[RTKCalculationConfig](
|
||||||
|
```
|
||||||
|
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||||
|
[IsUse] [int] NULL,
|
||||||
|
[MaxHorRTK] [float] NULL,
|
||||||
|
[MaxVerRTK] [float] NULL,
|
||||||
|
[RatioThrdRTK] [float] NULL,
|
||||||
|
[DeforMode] [int] NULL,
|
||||||
|
[SolvingStrategy] [int] NULL,
|
||||||
|
[RelatedProject] [int] NULL,
|
||||||
|
[FilterWindowSize] [float] NULL,
|
||||||
|
[SolveStoreInterval] [float] NULL,
|
||||||
|
CONSTRAINT [PK_RTKCalculationConfig] PRIMARY KEY CLUSTERED
|
||||||
|
(
|
||||||
|
[ID] ASC
|
||||||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
GO
|
||||||
|
/****** Object: Table [dbo].[StaticeCalculationConfig] Script Date: 2018/7/5 15:04:35 ******/
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
```sql
|
||||||
|
CREATE TABLE [dbo].[StaticeCalculationConfig](
|
||||||
|
```
|
||||||
|
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||||
|
[IsUse] [int] NULL,
|
||||||
|
[MaxHorSTC] [float] NULL,
|
||||||
|
[MaxVerSTC] [float] NULL,
|
||||||
|
[RatioThrdSTC] [float] NULL,
|
||||||
|
[SolvingStrategy] [int] NULL,
|
||||||
|
[SessLengthSTC] [int] NULL,
|
||||||
|
[CalcFreqSTC] [int] NULL,
|
||||||
|
[RelatedProject] [int] NULL,
|
||||||
|
CONSTRAINT [PK_StaticeMonitorConfig] PRIMARY KEY CLUSTERED
|
||||||
|
(
|
||||||
|
[ID] ASC
|
||||||
|
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||||
|
) ON [PRIMARY]
|
||||||
|
|
||||||
|
GO
|
||||||
|
SET IDENTITY_INSERT [dbo].[DynamicCalculationConfig] ON
|
||||||
|
|
||||||
|
```sql
|
||||||
|
INSERT [dbo].[DynamicCalculationConfig] ([ID], [IsUse], [SolveMode], [RobustMode], [RatioThrdDYN], [SolvingStrategy], [RelatedProject], [FilterWindowSize], [SolveStoreInterval]) VALUES (1, 0, 0, 0, 3, NULL, 2, 10, 30)
|
||||||
|
```
|
||||||
|
SET IDENTITY_INSERT [dbo].[DynamicCalculationConfig] OFF
|
||||||
|
SET IDENTITY_INSERT [dbo].[RoutineConfig] ON
|
||||||
|
|
||||||
|
```sql
|
||||||
|
INSERT [dbo].[RoutineConfig] ([ID], [RelatedProject], [ObsType], [ObsFreq], [Intervals], [EleCutOff], [ExcludeSats], [UsedSys], [IsSaveRawData], [SaveRawDataType], [SaveDataInterval]) VALUES (1, 2, 0, 0, 15, 12, NULL, N'0&1&2', 0, 0, 24)
|
||||||
|
```
|
||||||
|
SET IDENTITY_INSERT [dbo].[RoutineConfig] OFF
|
||||||
|
SET IDENTITY_INSERT [dbo].[RTKCalculationConfig] ON
|
||||||
|
|
||||||
|
```sql
|
||||||
|
INSERT [dbo].[RTKCalculationConfig] ([ID], [IsUse], [MaxHorRTK], [MaxVerRTK], [RatioThrdRTK], [DeforMode], [SolvingStrategy], [RelatedProject], [FilterWindowSize], [SolveStoreInterval]) VALUES (1, 1, 0.02, 0.04, 2.5, 0, 0, 2, 120, 30)
|
||||||
|
```
|
||||||
|
SET IDENTITY_INSERT [dbo].[RTKCalculationConfig] OFF
|
||||||
|
SET IDENTITY_INSERT [dbo].[StaticeCalculationConfig] ON INSERT [dbo].[StaticeCalculationConfig] ([ID], [IsUse], [MaxHorSTC], [MaxVerSTC], [RatioThrdSTC], [SolvingStrategy], [SessLengthSTC], [CalcFreqSTC], [RelatedProject]) VALUES (5, 0, 0.02, 0.02, 2.5, NULL, 5, 5, 12)
|
||||||
|
SET IDENTITY_INSERT [dbo].[StaticeCalculationConfig] OFF
|
||||||
54
实践积累/数据库/INDEX_数据库.md
Executable file
54
实践积累/数据库/INDEX_数据库.md
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
---
|
||||||
|
title: 数据库 索引
|
||||||
|
tags:
|
||||||
|
- 索引
|
||||||
|
created: 2026-04-21
|
||||||
|
---
|
||||||
|
|
||||||
|
# 数据库
|
||||||
|
|
||||||
|
> 自动生成的索引文件
|
||||||
|
|
||||||
|
## 文件列表
|
||||||
|
|
||||||
|
| 文件名 | 大小 | 说明 |
|
||||||
|
|--------|------|------|
|
||||||
|
| [[CAP定理(CAP theorem)]] | 1KB | |
|
||||||
|
| [[Cpu 占用过高]] | 420B | |
|
||||||
|
| [[HiMonitor1.0 升级到1.3脚本注意事项]] | 4KB | |
|
||||||
|
| [[MariaDB_Centos7安装mariadb,支持远程访问]] | 1KB | |
|
||||||
|
| [[PostgreSQL_Pg12 安装过程]] | 1KB | |
|
||||||
|
| [[PostgreSQL_Postgresql 帐号密码修改方法]] | 267B | |
|
||||||
|
| [[PostgreSQL_pg_hba.conf]] | 1KB | |
|
||||||
|
| [[PostgreSQL_postgresql删除还有活动连接的数据库]] | 246B | |
|
||||||
|
| [[PostgreSQL_systemctl start postgresql-12.service -- 启动服务]] | 223B | |
|
||||||
|
| [[SQL SERVER 游标使用]] | 2KB | |
|
||||||
|
| [[SQLSERVER 数据库恢复挂起的解决办法]] | 362B | |
|
||||||
|
| [[SQLSERVER存储过程基本语法]] | 6KB | |
|
||||||
|
| [[三峡数据变形值直接导出]] | 552B | |
|
||||||
|
| [[关系型数据库遵循ACID规则]] | 1KB | |
|
||||||
|
| [[内蒙古数据FTP推送脚本快速获取]] | 440B | |
|
||||||
|
| [[单个HiMonitor 站点数据]] | 873B | |
|
||||||
|
| [[去重]] | 229B | |
|
||||||
|
| [[合肥董铺水库中间数据]] | 2KB | |
|
||||||
|
| [[回补中间一段时间的GNSS数据]] | 1KB | |
|
||||||
|
| [[循环批量删除数据库表]] | 814B | |
|
||||||
|
| [[循环造固定数据值脚本]] | 744B | |
|
||||||
|
| [[循环遍历插数据]] | 591B | |
|
||||||
|
| [[批量创建app 表索引]] | 820B | |
|
||||||
|
| [[批量删除表]] | 458B | |
|
||||||
|
| [[批量删除超前数据脚本]] | 903B | |
|
||||||
|
| [[批量删除超前数据脚本(监测云)]] | 1KB | |
|
||||||
|
| [[批量增加非聚集索引]] | 1KB | |
|
||||||
|
| [[按日分组求均值]] | 221B | |
|
||||||
|
| [[新增站点基准信息增加]] | 547B | |
|
||||||
|
| [[无日志文件附加数据库失败解决]] | 1KB | |
|
||||||
|
| [[松滋 2号店循环造rtk]] | 1KB | |
|
||||||
|
| [[模拟一段数据]] | 1KB | |
|
||||||
|
| [[解除数据库占用连接]] | 491B | |
|
||||||
|
| [[运行中数据库收缩脚本]] | 743B | |
|
||||||
|
| [[链接服务器远程查询]] | 1B | |
|
||||||
|
| [[附加数据库]] | 105B | |
|
||||||
|
|
||||||
|
---
|
||||||
|
*共 36 个文件*
|
||||||
25
实践积累/数据库/MariaDB_Centos7安装mariadb,支持远程访问.md
Executable file
25
实践积累/数据库/MariaDB_Centos7安装mariadb,支持远程访问.md
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
1、安装MariaDB:yum -y install mariadb mariadb-server
|
||||||
|
2、设置开机启动:systemctl enable mariadb
|
||||||
|
3、启动MariaDB:systemctl start mariadb
|
||||||
|
4、初始化配置:mysql_secure_installation
|
||||||
|
4.1、设置密码,会提示先输入密码
|
||||||
|
Enter current password for root (enter for none):<–初次运行直接回车
|
||||||
|
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
|
||||||
|
New password: <– 设置root用户的密码
|
||||||
|
Re-enter new password: <– 再输入一次你设置的密码
|
||||||
|
4.2、其他配置
|
||||||
|
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
|
||||||
|
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
|
||||||
|
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
|
||||||
|
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车
|
||||||
|
初始化MariaDB完成,接下来测试登录
|
||||||
|
mysql -uroot -p你的密码
|
||||||
|
完成。
|
||||||
|
==5、设置远程登录:==
|
||||||
|
==使用mysql -uroot -p密码登录后,执行命令:==
|
||||||
|
==GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码的明文' WITH GRANT OPTION;==
|
||||||
|
==FLUSH PRIVILEGES;==
|
||||||
|
==6、如果远程访问,并且数据量很大,则需要进行如下配置,否则会出现==**MySQL server has gone away** ==的==
|
||||||
|
==错误 :==
|
||||||
|
==set global max_allowed_packet=1024*1024*16;==
|
||||||
|
> 来自 <[https://blog.csdn.net/lianshaohua/article/details/88380898](https://blog.csdn.net/lianshaohua/article/details/88380898)>
|
||||||
18
实践积累/数据库/PostgreSQL_Pg12 安装过程.md
Executable file
18
实践积累/数据库/PostgreSQL_Pg12 安装过程.md
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
1. ==Install the repository RPM:========yum install== ==https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm==
|
||||||
|
2. ==Install the client packages:========yum install postgresql12==
|
||||||
|
3. ==Optionally install the server packages:========yum install postgresql12-server==
|
||||||
|
4. ==Optionally initialize the database and enable automatic start:========/usr/pgsql-12/bin/postgresql-12-setup initdb========systemctl enable postgresql-12========systemctl start postgresql-12== > 来自 <[https://www.postgresql.org/download/linux/redhat/](https://www.postgresql.org/download/linux/redhat/)>
|
||||||
|
[Service]
|
||||||
|
Type=notify
|
||||||
|
|
||||||
|
User=postgres
|
||||||
|
Group=postgres
|
||||||
|
|
||||||
|
# Note: avoid inserting whitespace in these Environment= lines, or you may
|
||||||
|
# break postgresql-setup.
|
||||||
|
|
||||||
|
# Location of database directory
|
||||||
|
Environment=PGDATA=/var/lib/pgsql/12/data/
|
||||||
|
|
||||||
|
初始化之后,数据文件会存在 /var/lib/pgsql/12/data
|
||||||
|
> 来自 <[https://www.postgresql.org/download/linux/redhat/](https://www.postgresql.org/download/linux/redhat/)>
|
||||||
4
实践积累/数据库/PostgreSQL_Postgresql 帐号密码修改方法.md
Executable file
4
实践积累/数据库/PostgreSQL_Postgresql 帐号密码修改方法.md
Executable file
@@ -0,0 +1,4 @@
|
|||||||
|
==#su postgres== ======-bash-3.2$psql - postgres== ======postgres=#alter user postgres with password 'new password';== ==////====一定要加分号执行========postgres=#\q==
|
||||||
|
|
||||||
|
su - postgres
|
||||||
|
psql -U postgresalter user postgres with encrypted password '1';
|
||||||
11
实践积累/数据库/PostgreSQL_pg_hba.conf.md
Executable file
11
实践积累/数据库/PostgreSQL_pg_hba.conf.md
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
METHOD指定如何处理客户端的认证。常用的有ident,md5,password,trust,reject
|
||||||
|
ident是Linux下PostgreSQL默认的local认证方式,凡是能正确登录服务器的操作系统用户(注:不是数据库用户)就能使用本用户映射的数据库用户不需密码登录数据库。用户映射文件为pg_ident.conf,这个文件记录着与操作系统用户匹配的数据库用户,如果某操作系统用户在本文件中没有映射用户,则默认的映射数据库用户与操作系统用户同名。比如,服务器上有名为user1的操作系统用户,同时数据库上也有同名的数据库用户,user1登录操作系统后可以直接输入psql,以user1数据库用户身份登录数据库且不需密码。很多初学者都会遇到psql -U username登录数据库却出现“username ident 认证失败”的错误,明明数据库用户已经createuser。原因就在于此,使用了ident认证方式,却没有同名的操作系统用户或没有相应的映射用户。解决方案:1、在pg_ident.conf中添加映射用户;2、改变认证方式。
|
||||||
|
md5是常用的密码认证方式,如果你不使用ident,最好使用md5。密码是以md5形式传送给数据库,较安全,且不需建立同名的操作系统用户。
|
||||||
|
password是以明文密码传送给数据库,建议不要在生产环境中使用。
|
||||||
|
trust是只要知道数据库用户名就不需要密码或ident就能登录,建议不要在生产环境中使用。
|
||||||
|
reject是拒绝认证。
|
||||||
|
在文件查找 listen_addresses,他的值说明
|
||||||
|
如果希望只能从本地计算机访问PostgreSQL数据库,就将该项设置为'localhost';
|
||||||
|
如果希望从局域网访问PostgreSQL数据库,就将该项设置为PostgreSQL数据库的局域网IP地址;
|
||||||
|
如果希望从互联网访问PostgreSQL数据库,就将该项设置为PostgreSQL数据库的互联网IP地址;
|
||||||
|
如果希望从任何地方都可以访问PostgreSQL数据库,就将该配置项设置为“*”;
|
||||||
7
实践积累/数据库/PostgreSQL_postgresql删除还有活动连接的数据库.md
Executable file
7
实践积累/数据库/PostgreSQL_postgresql删除还有活动连接的数据库.md
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
```sql
|
||||||
|
select `pg_terminate_backend(pid)` from `pg_stat_activity` where `datname`='testdb' and `pid`<>`pg_backend_pid();`
|
||||||
|
```
|
||||||
|
==上面sql表示的是关闭数据库testdb的活动连接,接下来就可以用==
|
||||||
|
```sql
|
||||||
|
drop database `testdb;`
|
||||||
|
```
|
||||||
1
实践积累/数据库/PostgreSQL_systemctl start postgresql-12.service -- 启动服务.md
Executable file
1
实践积累/数据库/PostgreSQL_systemctl start postgresql-12.service -- 启动服务.md
Executable file
@@ -0,0 +1 @@
|
|||||||
|
systemctl start postgresql-12.service // 启动服务systemctl stop postgresql-12.service // 关闭服务systemctl restart postgresql-12.service // 重启服务systemctl status postgresql-12.service // 查看状态
|
||||||
72
实践积累/数据库/SQL SERVER 游标使用.md
Executable file
72
实践积累/数据库/SQL SERVER 游标使用.md
Executable file
@@ -0,0 +1,72 @@
|
|||||||
|
我们在处理数据的时候,经常会出现需要循环处理数据的需求,如果我们能用CTE或者其他语句处理的话,没有问题,但有时候往往处理起来比较困难,这时候我们可以选择使用游标处理,选择使用哪种形式,要考虑效率问题,一般游标效率不高,但也有适合使用的场景。
|
||||||
|
|
||||||
|
游标分为静态游标和动态游标,静态游标的数据是固定的,不会因为数据表的改变而改变;动态游标的数据是随着数据表变化而变化的,游标默认是动态游标,通过关键字STATIC设置,OK,上测试数据:
|
||||||
|
|
||||||
|
--测试数据
|
||||||
|
```sql
|
||||||
|
if not object_id(N'Tempdb..#T') is null
|
||||||
|
drop table #T
|
||||||
|
Go
|
||||||
|
Create table #T([id] int,[name] nvarchar(22))
|
||||||
|
Insert #T
|
||||||
|
select 1,N'张三' union all
|
||||||
|
select 2,N'李四' union all
|
||||||
|
select 3,N'王五' union all
|
||||||
|
select 4,N'赵六'
|
||||||
|
Go
|
||||||
|
```
|
||||||
|
--测试数据结束
|
||||||
|
我们先看静态游标的使用方法:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
DECLARE @id INT , @name NVARCHAR(50) --声明变量,需要读取的数据
|
||||||
|
DECLARE cur CURSOR STATIC --声明静态游标
|
||||||
|
```
|
||||||
|
FOR
|
||||||
|
```sql
|
||||||
|
SELECT * FROM #T
|
||||||
|
OPEN cur --打开游标
|
||||||
|
FETCH NEXT FROM cur INTO @id, @name --取数据
|
||||||
|
WHILE ( @@fetch_status = 0 ) --判断是否还有数据
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
```sql
|
||||||
|
SELECT '数据: ' + RTRIM(@id) + @name
|
||||||
|
UPDATE #T SET name='测试' WHERE id=4 --测试静态动态用
|
||||||
|
FETCH NEXT FROM cur INTO @id, @name --这里一定要写取下一条数据
|
||||||
|
```
|
||||||
|
END
|
||||||
|
CLOSE cur --关闭游标
|
||||||
|
DEALLOCATE cur
|
||||||
|
结果如下,我们可以看到ID是4的数据没有改变,依然是赵六,而不是UPDATE之后的测试:
|
||||||
|
|
||||||
|
我们再来看一下,动态游标,去掉STATIC关键字即可:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
DECLARE @id INT , @name NVARCHAR(50) --声明变量,需要读取的数据
|
||||||
|
DECLARE cur CURSOR --去掉STATIC关键字即可
|
||||||
|
```
|
||||||
|
FOR
|
||||||
|
```sql
|
||||||
|
SELECT * FROM #T
|
||||||
|
OPEN cur --打开游标
|
||||||
|
FETCH NEXT FROM cur INTO @id, @name --取数据
|
||||||
|
WHILE ( @@fetch_status = 0 ) --判断是否还有数据
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
```sql
|
||||||
|
SELECT '数据: ' + RTRIM(@id) + @name
|
||||||
|
UPDATE #T SET name='测试' WHERE id=4 --测试静态动态用
|
||||||
|
FETCH NEXT FROM cur INTO @id, @name --这里一定要写取下一条数据
|
||||||
|
```
|
||||||
|
END
|
||||||
|
CLOSE cur --关闭游标
|
||||||
|
DEALLOCATE cur
|
||||||
|
我们看结果,可以看到ID为4的数据已经更改为测试:
|
||||||
|
|
||||||
|
以上是游标的用法,以及动态、静态游标的介绍使用。
|
||||||
|
---------------------
|
||||||
|
作者:二月十六
|
||||||
|
来源:CSDN
|
||||||
|
原文:https://blog.csdn.net/sinat_28984567/article/details/79811887
|
||||||
|
版权声明:本文为博主原创文章,转载请附上博文链接!
|
||||||
17
实践积累/数据库/SQLSERVER 数据库恢复挂起的解决办法.md
Executable file
17
实践积累/数据库/SQLSERVER 数据库恢复挂起的解决办法.md
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
如果你的数据库还处于挂起状态,请把我下面代码的test改为你的库名,然后执行完,刷新就正常了:
|
||||||
|
USE master
|
||||||
|
GO
|
||||||
|
```sql
|
||||||
|
ALTER DATABASE test SET SINGLE_USER
|
||||||
|
GO
|
||||||
|
ALTER DATABASE test SET EMERGENCY
|
||||||
|
GO
|
||||||
|
```
|
||||||
|
DBCC CHECKDB(test,REPAIR_ALLOW_DATA_LOSS)
|
||||||
|
go
|
||||||
|
```sql
|
||||||
|
ALTER DATABASE test SET ONLINE
|
||||||
|
GO
|
||||||
|
ALTER DATABASE test SET MULTI_USER
|
||||||
|
GO
|
||||||
|
```
|
||||||
311
实践积累/数据库/SQLSERVER存储过程基本语法.md
Executable file
311
实践积累/数据库/SQLSERVER存储过程基本语法.md
Executable file
@@ -0,0 +1,311 @@
|
|||||||
|
一、定义变量
|
||||||
|
--简单赋值
|
||||||
|
```sql
|
||||||
|
declare @a int
|
||||||
|
set @a=5
|
||||||
|
print @a --使用select语句赋值
|
||||||
|
declare @user1 nvarchar(50)
|
||||||
|
select @user1='张三'
|
||||||
|
print @user1
|
||||||
|
declare @user2 nvarchar(50)
|
||||||
|
select @user2 = Name from ST_User where ID=1
|
||||||
|
print @user2 --使用update语句赋值
|
||||||
|
declare @user3 nvarchar(50)
|
||||||
|
update ST_User set @user3 = Name where ID=1
|
||||||
|
print @user3
|
||||||
|
|
||||||
|
```
|
||||||
|
二、表、临时表、表变量
|
||||||
|
|
||||||
|
--创建临时表1
|
||||||
|
```sql
|
||||||
|
create table #DU_User1
|
||||||
|
```
|
||||||
|
(
|
||||||
|
[ID] [int] NOT NULL,
|
||||||
|
[Oid] [int] NOT NULL,
|
||||||
|
[Login] [nvarchar](50) NOT NULL,
|
||||||
|
[Rtx] [nvarchar](4) NOT NULL,
|
||||||
|
[Name] [nvarchar](5) NOT NULL,
|
||||||
|
[Password] [nvarchar](max) NULL,
|
||||||
|
[State] [nvarchar](8) NOT NULL
|
||||||
|
);
|
||||||
|
--向临时表1插入一条记录
|
||||||
|
```sql
|
||||||
|
insert into #DU_User1 (ID,Oid,[Login],Rtx,Name,[Password],State) values (100,2,'LS','0000','临时','321','特殊'); --从ST_User查询数据,填充至新生成的临时表
|
||||||
|
select * into #DU_User2 from ST_User where ID<8 --查询并联合两临时表
|
||||||
|
select * from #DU_User2 where ID<3 union select * from #DU_User1 --删除两临时表
|
||||||
|
drop table #DU_User1
|
||||||
|
drop table #DU_User2 --创建临时表
|
||||||
|
CREATE TABLE #t
|
||||||
|
```
|
||||||
|
(
|
||||||
|
[ID] [int] NOT NULL,
|
||||||
|
[Oid] [int] NOT NULL,
|
||||||
|
[Login] [nvarchar](50) NOT NULL,
|
||||||
|
[Rtx] [nvarchar](4) NOT NULL,
|
||||||
|
[Name] [nvarchar](5) NOT NULL,
|
||||||
|
[Password] [nvarchar](max) NULL,
|
||||||
|
[State] [nvarchar](8) NOT NULL,
|
||||||
|
) --将查询结果集(多条数据)插入临时表
|
||||||
|
```sql
|
||||||
|
insert into #t select * from ST_User
|
||||||
|
```
|
||||||
|
--不能这样插入
|
||||||
|
--select * into #t from dbo.ST_User --添加一列,为int型自增长子段
|
||||||
|
```sql
|
||||||
|
alter table #t add [myid] int NOT NULL IDENTITY(1,1)
|
||||||
|
```
|
||||||
|
--添加一列,默认填充全球唯一标识
|
||||||
|
```sql
|
||||||
|
alter table #t add [myid1] uniqueidentifier NOT NULL default(newid()) select * from #t
|
||||||
|
drop table #t
|
||||||
|
```
|
||||||
|
--给查询结果集增加自增长列 --无主键时:
|
||||||
|
```sql
|
||||||
|
select IDENTITY(int,1,1)as ID, Name,[Login],[Password] into #t from ST_User
|
||||||
|
select * from #t --有主键时:
|
||||||
|
select (select SUM(1) from ST_User where ID<= a.ID) as myID,* from ST_User a order by myID
|
||||||
|
```
|
||||||
|
--定义表变量
|
||||||
|
```sql
|
||||||
|
declare @t table
|
||||||
|
```
|
||||||
|
(
|
||||||
|
id int not null,
|
||||||
|
msg nvarchar(50) null
|
||||||
|
)
|
||||||
|
```sql
|
||||||
|
insert into @t values(1,'1')
|
||||||
|
insert into @t values(2,'2')
|
||||||
|
select * from @t
|
||||||
|
```
|
||||||
|
三、循环
|
||||||
|
|
||||||
|
--while循环计算1到100的和
|
||||||
|
```sql
|
||||||
|
declare @a int
|
||||||
|
declare @sum int
|
||||||
|
set @a=1
|
||||||
|
set @sum=0
|
||||||
|
while @a<=100
|
||||||
|
```
|
||||||
|
begin
|
||||||
|
```sql
|
||||||
|
set @sum+=@a
|
||||||
|
set @a+=1
|
||||||
|
```
|
||||||
|
end
|
||||||
|
print @sum
|
||||||
|
四、条件语句
|
||||||
|
|
||||||
|
--if,else条件分支
|
||||||
|
if(1+1=2)
|
||||||
|
begin
|
||||||
|
print '对'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
print '错'
|
||||||
|
```sql
|
||||||
|
end --when then条件分支
|
||||||
|
declare @today int
|
||||||
|
declare @week nvarchar(3)
|
||||||
|
set @today=3
|
||||||
|
set @week=case
|
||||||
|
```
|
||||||
|
when @today=1 then '星期一'
|
||||||
|
when @today=2 then '星期二'
|
||||||
|
when @today=3 then '星期三'
|
||||||
|
when @today=4 then '星期四'
|
||||||
|
when @today=5 then '星期五'
|
||||||
|
when @today=6 then '星期六'
|
||||||
|
when @today=7 then '星期日'
|
||||||
|
else '值错误'
|
||||||
|
end
|
||||||
|
```sql
|
||||||
|
print @week
|
||||||
|
|
||||||
|
```
|
||||||
|
五、游标
|
||||||
|
|
||||||
|
```sql
|
||||||
|
declare @ID int
|
||||||
|
declare @Oid int
|
||||||
|
declare @Login varchar(50) --定义一个游标
|
||||||
|
declare user_cur cursor for select ID,Oid,[Login] from ST_User
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open user_cur
|
||||||
|
while @@fetch_status=0
|
||||||
|
```
|
||||||
|
begin
|
||||||
|
--读取游标
|
||||||
|
```sql
|
||||||
|
fetch next from user_cur into @ID,@Oid,@Login
|
||||||
|
print @ID
|
||||||
|
```
|
||||||
|
--print @Login
|
||||||
|
end
|
||||||
|
close user_cur
|
||||||
|
--摧毁游标
|
||||||
|
deallocate user_cur
|
||||||
|
六、触发器
|
||||||
|
|
||||||
|
触发器中的临时表:
|
||||||
|
|
||||||
|
Inserted
|
||||||
|
存放进行insert和update 操作后的数据
|
||||||
|
Deleted
|
||||||
|
存放进行delete 和update操作前的数据
|
||||||
|
|
||||||
|
--创建触发器
|
||||||
|
```sql
|
||||||
|
Create trigger User_OnUpdate
|
||||||
|
```
|
||||||
|
On ST_User
|
||||||
|
for Update
|
||||||
|
As
|
||||||
|
```sql
|
||||||
|
declare @msg nvarchar(50)
|
||||||
|
```
|
||||||
|
--@msg记录修改情况
|
||||||
|
```sql
|
||||||
|
select @msg = N'姓名从“' + Deleted.Name + N'”修改为“' + Inserted.Name + '”' from Inserted,Deleted
|
||||||
|
```
|
||||||
|
--插入日志表
|
||||||
|
```sql
|
||||||
|
insert into [LOG](MSG)values(@msg) --删除触发器
|
||||||
|
drop trigger User_OnUpdate
|
||||||
|
```
|
||||||
|
七、存储过程
|
||||||
|
|
||||||
|
--创建带output参数的存储过程
|
||||||
|
```sql
|
||||||
|
CREATE PROCEDURE PR_Sum
|
||||||
|
```
|
||||||
|
@a int,
|
||||||
|
@b int,
|
||||||
|
@sum int output
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
```sql
|
||||||
|
set @sum=@a+@b
|
||||||
|
END --创建Return返回值存储过程
|
||||||
|
CREATE PROCEDURE PR_Sum2
|
||||||
|
```
|
||||||
|
@a int,
|
||||||
|
@b int
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
Return @a+@b
|
||||||
|
```sql
|
||||||
|
END --执行存储过程获取output型返回值
|
||||||
|
declare @mysum int
|
||||||
|
execute PR_Sum 1,2,@mysum output
|
||||||
|
print @mysum --执行存储过程获取Return型返回值
|
||||||
|
declare @mysum2 int
|
||||||
|
execute @mysum2= PR_Sum2 1,2
|
||||||
|
print @mysum2
|
||||||
|
```
|
||||||
|
八、自定义函数
|
||||||
|
|
||||||
|
函数的分类:
|
||||||
|
|
||||||
|
1)标量值函数
|
||||||
|
|
||||||
|
2)表值函数
|
||||||
|
|
||||||
|
a:内联表值函数
|
||||||
|
|
||||||
|
b:多语句表值函数
|
||||||
|
|
||||||
|
3)系统函数
|
||||||
|
|
||||||
|
--新建标量值函数
|
||||||
|
```sql
|
||||||
|
create function FUNC_Sum1
|
||||||
|
```
|
||||||
|
(
|
||||||
|
@a int,
|
||||||
|
@b int
|
||||||
|
)
|
||||||
|
returns int
|
||||||
|
as
|
||||||
|
begin
|
||||||
|
return @a+@b
|
||||||
|
```sql
|
||||||
|
end --新建内联表值函数
|
||||||
|
create function FUNC_UserTab_1
|
||||||
|
```
|
||||||
|
(
|
||||||
|
@myId int
|
||||||
|
)
|
||||||
|
returns table
|
||||||
|
as
|
||||||
|
return (select * from ST_User where ID<@myId) --新建多语句表值函数
|
||||||
|
```sql
|
||||||
|
create function FUNC_UserTab_2
|
||||||
|
```
|
||||||
|
(
|
||||||
|
@myId int
|
||||||
|
)
|
||||||
|
returns @t table
|
||||||
|
(
|
||||||
|
[ID] [int] NOT NULL,
|
||||||
|
[Oid] [int] NOT NULL,
|
||||||
|
[Login] [nvarchar](50) NOT NULL,
|
||||||
|
[Rtx] [nvarchar](4) NOT NULL,
|
||||||
|
[Name] [nvarchar](5) NOT NULL,
|
||||||
|
[Password] [nvarchar](max) NULL,
|
||||||
|
[State] [nvarchar](8) NOT NULL
|
||||||
|
)
|
||||||
|
as
|
||||||
|
begin
|
||||||
|
```sql
|
||||||
|
insert into @t select * from ST_User where ID<@myId
|
||||||
|
```
|
||||||
|
return
|
||||||
|
```sql
|
||||||
|
end --调用表值函数
|
||||||
|
select * from dbo.FUNC_UserTab_1(15)
|
||||||
|
```
|
||||||
|
--调用标量值函数
|
||||||
|
```sql
|
||||||
|
declare @s int
|
||||||
|
set @s=dbo.FUNC_Sum1(100,50)
|
||||||
|
print @s --删除标量值函数
|
||||||
|
drop function FUNC_Sum1
|
||||||
|
```
|
||||||
|
谈谈自定义函数与存储过程的区别:
|
||||||
|
|
||||||
|
一、自定义函数:
|
||||||
|
|
||||||
|
1. 可以返回表变量
|
||||||
|
|
||||||
|
2. 限制颇多,包括
|
||||||
|
|
||||||
|
不能使用output参数;
|
||||||
|
|
||||||
|
不能用临时表;
|
||||||
|
|
||||||
|
函数内部的操作不能影响到外部环境;
|
||||||
|
|
||||||
|
不能通过select返回结果集;
|
||||||
|
|
||||||
|
不能update,delete,数据库表;
|
||||||
|
|
||||||
|
3. 必须return 一个标量值或表变量
|
||||||
|
|
||||||
|
自定义函数一般用在复用度高,功能简单单一,争对性强的地方。
|
||||||
|
|
||||||
|
二、存储过程
|
||||||
|
|
||||||
|
1. 不能返回表变量
|
||||||
|
|
||||||
|
2. 限制少,可以执行对数据库表的操作,可以返回数据集
|
||||||
|
|
||||||
|
3. 可以return一个标量值,也可以省略return
|
||||||
|
|
||||||
|
存储过程一般用在实现复杂的功能,数据操纵方面。
|
||||||
26
实践积累/数据库/三峡数据变形值直接导出.md
Executable file
26
实践积累/数据库/三峡数据变形值直接导出.md
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
/****** Script for SelectTopNRows command from SSMS ******/
|
||||||
|
|
||||||
|
```sql
|
||||||
|
declare @bx float
|
||||||
|
declare @by float
|
||||||
|
declare @bh float
|
||||||
|
select @bx=a.BaseX,@by=a.BaseY,@bh=a.BaseH from DataSyncPushConnector.dbo.DataSyncStation a
|
||||||
|
join [HiMonitorDB].[dbo].DeviceInfo b
|
||||||
|
```
|
||||||
|
on a.DeviceName=b.DeviceName
|
||||||
|
```sql
|
||||||
|
where a.DeviceName='WZ0504'
|
||||||
|
|
||||||
|
SELECT [GPSIndex]
|
||||||
|
```
|
||||||
|
,[aDatetime]
|
||||||
|
,[X]
|
||||||
|
,[Y]
|
||||||
|
,[Height]
|
||||||
|
,([X]-@bx)*1000 as dx
|
||||||
|
,([Y]-@by)*1000 as dy
|
||||||
|
,([Height]-@bh)*1000 as dh
|
||||||
|
```sql
|
||||||
|
FROM [HiMonitorDB].[dbo].[wz0504_stc] a where aDatetime >'2020-04-1'
|
||||||
|
```
|
||||||
|
order by aDatetime desc
|
||||||
14
实践积累/数据库/关系型数据库遵循ACID规则.md
Executable file
14
实践积累/数据库/关系型数据库遵循ACID规则.md
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
**关系型数据库遵循ACID规则**
|
||||||
|
==事务在英文中是transaction,和现实世界中的交易很类似,它有如下四个特性:==
|
||||||
|
**1、A (Atomicity) 原子性**
|
||||||
|
==原子性很容易理解,也就是说事务里的所有操作要么全部做完,要么都不做,事务成功的条件是事务里的所有操作都成功,只要有一个操作失败,整个事务就失败,需要回滚。==
|
||||||
|
==比如银行转账,从A账户转100元至B账户,分为两个步骤:1)从A账户取100元;2)存入100元至B账户。这两步要么一起完成,要么一起不完成,如果只完成第一步,第二步失败,钱会莫名其妙少了100元。==
|
||||||
|
**2、C (Consistency) 一致性**
|
||||||
|
==一致性也比较容易理解,也就是说数据库要一直处于一致的状态,事务的运行不会改变数据库原本的一致性约束。==
|
||||||
|
==例如现有完整性约束a+b=10,如果一个事务改变了a,那么必须得改变b,使得事务结束后依然满足a+b=10,否则事务失败。==
|
||||||
|
**3、I (Isolation) 独立性**
|
||||||
|
==所谓的独立性是指并发的事务之间不会互相影响,如果一个事务要访问的数据正在被另外一个事务修改,只要另外一个事务未提交,它所访问的数据就不受未提交事务的影响。==
|
||||||
|
==比如现在有个交易是从A账户转100元至B账户,在这个交易还未完成的情况下,如果此时B查询自己的账户,是看不到新增加的100元的。==
|
||||||
|
**4、D (Durability) 持久性**
|
||||||
|
==持久性是指一旦事务提交后,它所做的修改将会永久的保存在数据库上,即使出现宕机也不会丢失。==
|
||||||
|
> 来自 <[http://www.runoob.com/mongodb/nosql.html](http://www.runoob.com/mongodb/nosql.html)>
|
||||||
12
实践积累/数据库/内蒙古数据FTP推送脚本快速获取.md
Executable file
12
实践积累/数据库/内蒙古数据FTP推送脚本快速获取.md
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
```sql
|
||||||
|
select a.DeviceName,b.ProjectID,a.id as DeviceId,a.MonTypeID,b.StationCode, b.Latitude as B ,b.Longitude as L,c.ConvertXValue as OriginX,c.ConvertYValue as OriginY,c.ConvertZValue as OriginZ from safeMonitorMgr.dbo.Mgr_Device as a
|
||||||
|
right join safeMonitorMgr.dbo.station as b
|
||||||
|
```
|
||||||
|
on a.StationID=b.Id
|
||||||
|
```sql
|
||||||
|
right join safeMonitorMgr.dbo.HimonitorSyncConfig as c
|
||||||
|
```
|
||||||
|
on c.DeviceID=a.id
|
||||||
|
```sql
|
||||||
|
where b.ProjectID =84 or b.ProjectID=85
|
||||||
|
```
|
||||||
26
实践积累/数据库/单个HiMonitor 站点数据.md
Executable file
26
实践积累/数据库/单个HiMonitor 站点数据.md
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
```sql
|
||||||
|
declare @dt datetime --时间
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
```
|
||||||
|
--declare @GPSINDEX1 bigint
|
||||||
|
```sql
|
||||||
|
declare @adatetime1 datetime
|
||||||
|
declare @endDate datetime; --结束时间
|
||||||
|
declare @X1 float
|
||||||
|
declare @Y1 float
|
||||||
|
declare @H1 float
|
||||||
|
declare @DX1 float
|
||||||
|
declare @DY1 float
|
||||||
|
declare @DH1 float
|
||||||
|
set @dt = GETDATE();
|
||||||
|
|
||||||
|
set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt) SET @DX1 = (rand()*-10 + 10)/4000
|
||||||
|
SET @DY1 = (rand()*-10 + 9)/4000
|
||||||
|
SET @DH1 =(rand()*-10 + 8)/4000
|
||||||
|
SET @X1 = 4877965.53002158+ @DX1
|
||||||
|
SET @Y1 = 537751.2022376+ @DY1
|
||||||
|
SET @H1 = 888.1181+ @DH1
|
||||||
|
SET @adatetime1 = DATEADD(S,@gpsindex/1000,'1970-01-01 00:00:00')
|
||||||
|
insert into HiMonitorDb.[dbo].plq_4_STC([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])VALUES(@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1)
|
||||||
|
```
|
||||||
15
实践积累/数据库/去重.md
Executable file
15
实践积累/数据库/去重.md
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
begin tran
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select distinct * into #temp from DataSyncStationSX
|
||||||
|
delete DataSyncStationSX
|
||||||
|
go
|
||||||
|
insert DataSyncStationSX select * from #temp Sqlclub
|
||||||
|
go
|
||||||
|
drop table #temp
|
||||||
|
|
||||||
|
select * from DataSyncStationSX
|
||||||
|
```
|
||||||
|
order by sid
|
||||||
|
|
||||||
|
commit
|
||||||
103
实践积累/数据库/合肥董铺水库中间数据.md
Executable file
103
实践积累/数据库/合肥董铺水库中间数据.md
Executable file
@@ -0,0 +1,103 @@
|
|||||||
|
```sql
|
||||||
|
USE [ZHDMTProj]
|
||||||
|
GO
|
||||||
|
|
||||||
|
```
|
||||||
|
/****** Object: StoredProcedure [dbo].[sp_ZHDMTProjProcedure20190615] Script Date: 2019/6/14 14:28:33 ******/
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE proc [dbo].[sp_ZHDMTProjProcedure20190615]
|
||||||
|
```
|
||||||
|
(
|
||||||
|
@stationName nvarchar(500),
|
||||||
|
@dt datetime,
|
||||||
|
@endDate datetime
|
||||||
|
)
|
||||||
|
as --declare @dt datetime --时间
|
||||||
|
```sql
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
declare @count int --计数
|
||||||
|
```
|
||||||
|
--declare @GPSINDEX1 bigint
|
||||||
|
```sql
|
||||||
|
declare @adatetime1 datetime
|
||||||
|
```
|
||||||
|
--declare @endDate datetime; --结束时间
|
||||||
|
```sql
|
||||||
|
declare @X1 float
|
||||||
|
declare @Y1 float
|
||||||
|
declare @H1 float
|
||||||
|
declare @DX1 float
|
||||||
|
declare @DY1 float
|
||||||
|
declare @DH1 float
|
||||||
|
declare @DX0 float
|
||||||
|
declare @DY0 float
|
||||||
|
declare @DH0 float
|
||||||
|
declare @X0 float
|
||||||
|
declare @Y0 float
|
||||||
|
declare @H0 float
|
||||||
|
declare @SELECT_SQL1 nvarchar(500)
|
||||||
|
declare @INSERT_SQL1 nvarchar(500)
|
||||||
|
```
|
||||||
|
吴 卓山 于 2019-06-14 14:28 修改
|
||||||
|
--set @dt = '2018-05-22 09:08:00.000';
|
||||||
|
--set @endDate= '2018-12-13 11:19:00.000';
|
||||||
|
--select @X1 = X,@Y1 = Y,@H1 = Height,@DX1=dltaX,@DY1=dltaY,@DH1=dltaH from MYB1_RTK where aDatetime = @dt
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT @X0 =[Sx] , @Y0=[Sy] , @H0 =[Sh] --去station表拿基准
|
||||||
|
FROM [ZHDMTProj].[dbo].[station] where sName=@stationName
|
||||||
|
|
||||||
|
|
||||||
|
SET @SELECT_SQL1='SELECT top 1 @DX0=dltaX , @DY0=dltaY , @DH0 =dltaH
|
||||||
|
FROM [ZHDMTProj].[dbo].'+ @stationName+' order by aDatetime desc';
|
||||||
|
EXEC sp_executesql @SELECT_SQL1, N'@DX0 float out,@DY0 float out,@DH0 float out,@stationName nvarchar(500)',@DX0 out,@DY0 out,@DH0 out,@stationName
|
||||||
|
|
||||||
|
```
|
||||||
|
--求出基准坐标
|
||||||
|
--set @X0=@X1-@DX1
|
||||||
|
--set @Y0=@Y1-@DY1
|
||||||
|
--set @H0=@H1-@DH1
|
||||||
|
```sql
|
||||||
|
select @X0,@Y0,@H0
|
||||||
|
```
|
||||||
|
while(@dt < @endDate) begin
|
||||||
|
```sql
|
||||||
|
set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt)
|
||||||
|
SET @DX1 = @DX0+(rand()*-2 + 1.2)
|
||||||
|
SET @DY1 =@DY0+ (rand()*-2 +1.2)
|
||||||
|
SET @DH1 =@DH0+(rand()*-2 + 1.2)
|
||||||
|
SET @X1 = @X0+ @DX1/1000
|
||||||
|
SET @Y1 = @Y0+ @DY1/1000
|
||||||
|
SET @H1 = @H0+ @DH1/1000
|
||||||
|
SET @adatetime1 = DATEADD(S,@gpsindex/1000,'1970-01-01 00:00:00')
|
||||||
|
BEGIN TRY SET @INSERT_SQL1=' insert into [ZHDMTProj].[dbo].'+ @stationName+'
|
||||||
|
```
|
||||||
|
([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])
|
||||||
|
VALUES(@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1)'
|
||||||
|
|
||||||
|
```sql
|
||||||
|
EXEC sp_executesql @INSERT_SQL1,
|
||||||
|
```
|
||||||
|
N'@gpsindex bigint,@adatetime1 datetime,@X1 float,@Y1 float,@H1 float,@DX1 float,@DY1 float,@DH1 float'
|
||||||
|
,@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1
|
||||||
|
|
||||||
|
--insert into [ZHDMTProj].[dbo].LY03([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])VALUES(@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1) END TRY
|
||||||
|
BEGIN
|
||||||
|
CATCH END CATCH
|
||||||
|
--****************
|
||||||
|
```sql
|
||||||
|
set @count = @count + 1
|
||||||
|
set @dt = DATEADD(HOUR,1,@dt) --每次递增5min
|
||||||
|
```
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
GO
|
||||||
52
实践积累/数据库/回补中间一段时间的GNSS数据.md
Executable file
52
实践积累/数据库/回补中间一段时间的GNSS数据.md
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
```sql
|
||||||
|
declare @dt datetime --时间
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
declare @count int --计数
|
||||||
|
```
|
||||||
|
--declare @GPSINDEX1 bigint
|
||||||
|
```sql
|
||||||
|
declare @adatetime1 datetime
|
||||||
|
declare @endDate datetime; --结束时间
|
||||||
|
declare @X1 float
|
||||||
|
declare @Y1 float
|
||||||
|
declare @H1 float
|
||||||
|
declare @DX1 float
|
||||||
|
declare @DY1 float
|
||||||
|
declare @DH1 float
|
||||||
|
declare @X0 float
|
||||||
|
declare @Y0 float
|
||||||
|
declare @H0 float
|
||||||
|
|
||||||
|
set @dt = '2020-1-17 12:30:00.000';
|
||||||
|
set @endDate= '2020-5-18 18:00:00.000';
|
||||||
|
select top 1 @X1 = X,@Y1 = Y,@H1 = Height,@DX1=dltaX,@DY1=dltaY,@DH1=dltaH from DC_GB09_STC where aDatetime < @dt order by aDatetime desc
|
||||||
|
```
|
||||||
|
--求出基准坐标
|
||||||
|
```sql
|
||||||
|
set @X0=@X1-@DX1
|
||||||
|
set @Y0=@Y1-@DY1
|
||||||
|
set @H0=@H1-@DH1
|
||||||
|
select @X0,@Y0,@H0
|
||||||
|
```
|
||||||
|
while(@dt < @endDate) begin
|
||||||
|
|
||||||
|
```sql
|
||||||
|
set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt)
|
||||||
|
SET @DX1 = RAND()*8-8/2;
|
||||||
|
SET @DY1 = RAND()*8-8/2;
|
||||||
|
SET @DH1 = RAND()*10-10/2;
|
||||||
|
SET @X1 = @X0+ @DX1/1000
|
||||||
|
SET @Y1 = @Y0+ @DY1/1000
|
||||||
|
SET @H1 = @H1+ @DH1/1000
|
||||||
|
SET @adatetime1 = DATEADD(S,@gpsindex/1000,'1970-01-01 00:00:00')
|
||||||
|
BEGIN TRY insert into DC_GB09_STC([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])VALUES(@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1)
|
||||||
|
END TRY BEGIN
|
||||||
|
```
|
||||||
|
CATCH END CATCH
|
||||||
|
--****************
|
||||||
|
```sql
|
||||||
|
set @count = @count + 1
|
||||||
|
set @dt = DATEADD(MINUTE,30,@dt) --每次递增5min
|
||||||
|
```
|
||||||
|
end
|
||||||
55
实践积累/数据库/循环批量删除数据库表.md
Executable file
55
实践积累/数据库/循环批量删除数据库表.md
Executable file
@@ -0,0 +1,55 @@
|
|||||||
|
--创建临时表
|
||||||
|
```sql
|
||||||
|
create table #Man(
|
||||||
|
```
|
||||||
|
id int identity(1,1),
|
||||||
|
tbName nvarchar(50)
|
||||||
|
) --往临时表插入数据
|
||||||
|
```sql
|
||||||
|
insert into #Man
|
||||||
|
select name from sys.tables
|
||||||
|
where create_date<='2018-03-10 15:36:35.687' and name not in ('DeviceNetState','EphInfo','FilterStatistic','UserInfo','AlmInfo')
|
||||||
|
```
|
||||||
|
order by create_date desc
|
||||||
|
|
||||||
|
--确认
|
||||||
|
```sql
|
||||||
|
select * from #Man
|
||||||
|
|
||||||
|
```
|
||||||
|
commit
|
||||||
|
rollback
|
||||||
|
begin tran
|
||||||
|
|
||||||
|
|
||||||
|
--定义循环变量
|
||||||
|
```sql
|
||||||
|
declare @i int
|
||||||
|
set @i = 1
|
||||||
|
declare @count int
|
||||||
|
select @count = count(*) from #Man
|
||||||
|
|
||||||
|
```
|
||||||
|
--print @count
|
||||||
|
|
||||||
|
```sql
|
||||||
|
declare @str nvarchar(500)
|
||||||
|
declare @tb nvarchar(50)
|
||||||
|
|
||||||
|
```
|
||||||
|
while(@i <= @count) begin
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select @tb = isnull(tbName, '') from #Man where id = @i
|
||||||
|
```
|
||||||
|
--循环执行语句
|
||||||
|
```sql
|
||||||
|
set @str = 'drop table [' + @tb+ ']'
|
||||||
|
```
|
||||||
|
exec(@str)
|
||||||
|
|
||||||
|
```sql
|
||||||
|
set @str = ''
|
||||||
|
set @i = @i + 1
|
||||||
|
```
|
||||||
|
end
|
||||||
33
实践积累/数据库/循环造固定数据值脚本.md
Executable file
33
实践积累/数据库/循环造固定数据值脚本.md
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
--
|
||||||
|
```sql
|
||||||
|
declare @BeginDate datetime
|
||||||
|
declare @EndDate datetime
|
||||||
|
|
||||||
|
declare @water1 float
|
||||||
|
declare @water2 float
|
||||||
|
|
||||||
|
declare @gpsIndex nvarchar(50)
|
||||||
|
|
||||||
|
set @BeginDate = '2018-08-27 00:00:00.000'
|
||||||
|
set @EndDate = '2018-08-27 18:59:59.997'
|
||||||
|
set @water1 = 2.16
|
||||||
|
set @water2 = 1.07
|
||||||
|
|
||||||
|
```
|
||||||
|
while(@BeginDate < @EndDate) begin
|
||||||
|
```sql
|
||||||
|
set @gpsIndex =convert(nvarchar(50),convert(bigint, datediff(ss, '1970-01-01 00:00:00', @BeginDate))*1000 + datepart(ms,@BeginDate))
|
||||||
|
|
||||||
|
insert into [ZHDMTProj].[dbo].[库水位1] ([GPSIndex],[aDatetime],[X])
|
||||||
|
```
|
||||||
|
values(@gpsIndex, @BeginDate, @water1)
|
||||||
|
```sql
|
||||||
|
insert into [ZHDMTProj].[dbo].[库水位2] ([GPSIndex],[aDatetime],[X])
|
||||||
|
```
|
||||||
|
values(@gpsIndex, @BeginDate, @water2)
|
||||||
|
|
||||||
|
--
|
||||||
|
```sql
|
||||||
|
set @BeginDate=DATEADD(MINUTE,1,@BeginDate)
|
||||||
|
```
|
||||||
|
end
|
||||||
26
实践积累/数据库/循环遍历插数据.md
Executable file
26
实践积累/数据库/循环遍历插数据.md
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
```sql
|
||||||
|
declare @x numeric(18,2) --X
|
||||||
|
declare @dt datetime --时间
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
declare @count int --计数
|
||||||
|
|
||||||
|
set @x = 0
|
||||||
|
set @count = 1
|
||||||
|
set @dt = '2018-07-02 12:00:00'
|
||||||
|
|
||||||
|
```
|
||||||
|
while(@dt < getdate()) begin
|
||||||
|
|
||||||
|
```sql
|
||||||
|
set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt)
|
||||||
|
|
||||||
|
|
||||||
|
insert into [ZHDMTProj].[dbo].[Flowmeter01]([GPSIndex],[aDatetime],[X]) values(@gpsindex, @dt, @x) --目标表
|
||||||
|
```
|
||||||
|
--****************
|
||||||
|
```sql
|
||||||
|
set @count = @count + 1
|
||||||
|
set @dt = DATEADD(ss,15,@dt) --每次递增30秒
|
||||||
|
```
|
||||||
|
end
|
||||||
36
实践积累/数据库/批量创建app 表索引.md
Executable file
36
实践积累/数据库/批量创建app 表索引.md
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
```sql
|
||||||
|
use safeMonitorApp
|
||||||
|
```
|
||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%_App' --or TABLE_NAME like '%_App_'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--创建非聚集索引
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('create NONCLUSTERED INDEX '+'IX_'+@tbname+ ' ON '+@tbname+ '([deviceId] ASC,[CollectTime] DESC)')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标
|
||||||
|
DEALLOCATE C_userID;
|
||||||
19
实践积累/数据库/批量删除表.md
Executable file
19
实践积累/数据库/批量删除表.md
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
--------参数定义------------------- DECLARE @Table NVARCHAR(30)
|
||||||
|
```sql
|
||||||
|
DECLARE tmpCur CURSOR FOR
|
||||||
|
SELECT name FROM sys.objects WHERE TYPE='U' AND name LIKE N'%_SRC%' --删除所有含有"_QueryLog"的表
|
||||||
|
OPEN tmpCur
|
||||||
|
FETCH NEXT FROM tmpCur INTO @Table WHILE @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
```sql
|
||||||
|
DECLARE @sql VARCHAR(100)
|
||||||
|
SELECT @sql = 'drop table ' + @Table
|
||||||
|
```
|
||||||
|
EXEC(@sql)
|
||||||
|
```sql
|
||||||
|
FETCH NEXT FROM tmpCur INTO @Table
|
||||||
|
```
|
||||||
|
END
|
||||||
|
CLOSE tmpCur
|
||||||
|
DEALLOCATE tmpCur
|
||||||
40
实践积累/数据库/批量删除超前数据脚本.md
Executable file
40
实践积累/数据库/批量删除超前数据脚本.md
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
begin tran
|
||||||
|
commit
|
||||||
|
--rollback
|
||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%_STC' or TABLE_NAME like '%_DYN' or TABLE_NAME like '%_RTK'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--删除未来的数据
|
||||||
|
--DELETE
|
||||||
|
--FROM [HiMonitorDB].[dbo].[11350069_STC]
|
||||||
|
--WHERE aDatetime >'2020-02-03'
|
||||||
|
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('delete from [HiMonitorDB].[dbo].['+@tbname+'] where aDatetime>getdate()')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标
|
||||||
|
DEALLOCATE C_userID;
|
||||||
77
实践积累/数据库/批量删除超前数据脚本(监测云).md
Executable file
77
实践积累/数据库/批量删除超前数据脚本(监测云).md
Executable file
@@ -0,0 +1,77 @@
|
|||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%2020_SRC'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--删除未来的数据
|
||||||
|
--DELETE
|
||||||
|
--FROM [HiMonitorDB].[dbo].[11350069_STC]
|
||||||
|
--WHERE aDatetime >'2020-02-03'
|
||||||
|
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('delete from [safeMonitorSrc].[dbo].['+@tbname+'] where CollectTime>GETDATE()')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标
|
||||||
|
DEALLOCATE C_userID;
|
||||||
|
|
||||||
|
begin tran
|
||||||
|
COMMIT
|
||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%2020_APP'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--删除未来的数据
|
||||||
|
--DELETE
|
||||||
|
--FROM [HiMonitorDB].[dbo].[11350069_STC]
|
||||||
|
--WHERE aDatetime >'2020-02-03'
|
||||||
|
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('delete from [safeMonitorAPP].[dbo].['+@tbname+'] where CollectTime>GETDATE()')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标
|
||||||
|
DEALLOCATE C_userID;
|
||||||
66
实践积累/数据库/批量增加非聚集索引.md
Executable file
66
实践积累/数据库/批量增加非聚集索引.md
Executable file
@@ -0,0 +1,66 @@
|
|||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%_clean'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--创建非聚集索引
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('create NONCLUSTERED INDEX '+'IX_'+@tbname+ ' ON '+@tbname+ '([Style] ASC,[aDatetime] DESC)')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标
|
||||||
|
DEALLOCATE C_userID;
|
||||||
|
|
||||||
|
--声明一个变量
|
||||||
|
```sql
|
||||||
|
declare @tbname as nvarchar(100);
|
||||||
|
```
|
||||||
|
--声明一个游标用来遍历查询到的结果
|
||||||
|
```sql
|
||||||
|
declare C_userID CURSOR for
|
||||||
|
select distinct TABLE_NAME from information_schema.COLUMNS
|
||||||
|
where TABLE_NAME like '%_2020_APP'
|
||||||
|
```
|
||||||
|
--打开游标
|
||||||
|
```sql
|
||||||
|
open C_userID;
|
||||||
|
```
|
||||||
|
--获取游标指向的数据
|
||||||
|
```sql
|
||||||
|
fetch next from C_userID into @tbname;
|
||||||
|
while @@FETCH_STATUS = 0
|
||||||
|
```
|
||||||
|
BEGIN
|
||||||
|
--执行具体的操作
|
||||||
|
--创建非聚集索引
|
||||||
|
--create NONCLUSTERED INDEX 索引名称 ON 表名(字段名)
|
||||||
|
EXEC('create NONCLUSTERED INDEX '+'IX_'+@tbname+ ' ON '+@tbname+ '([DeviceId] ASC,[CollectTime] DESC)')
|
||||||
|
--游标指向下一条数据
|
||||||
|
```sql
|
||||||
|
FETCH next from C_userID into @tbname;
|
||||||
|
```
|
||||||
|
END
|
||||||
|
--关闭游标
|
||||||
|
CLose C_userID
|
||||||
|
--释放游标 DEALLOCATE C_userID;
|
||||||
7
实践积累/数据库/按日分组求均值.md
Executable file
7
实践积累/数据库/按日分组求均值.md
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
SELECT
|
||||||
|
convert(char(10),aDatetime,120)
|
||||||
|
,round(avg([X]),6)
|
||||||
|
,round(avg([Y]),6)
|
||||||
|
,round(avg([Height]),6) FROM [ZHDMTProj].[dbo].[TLDZ1]
|
||||||
|
group by ( convert(char(10),aDatetime,120))
|
||||||
|
order by ( convert(char(10),aDatetime,120))
|
||||||
14
实践积累/数据库/新增站点基准信息增加.md
Executable file
14
实践积累/数据库/新增站点基准信息增加.md
Executable file
@@ -0,0 +1,14 @@
|
|||||||
|
```sql
|
||||||
|
use HiMonitorDB;
|
||||||
|
select * from DataSyncStationSX
|
||||||
|
where sname in ('GJ1201','GB1201','GB1202','GB1203','GB1204','GB1205','GB1206')
|
||||||
|
begin tran
|
||||||
|
exec sp_NDrefrenceValue 'GB1201','2019-05-1 00:00:00.000',0,0,0
|
||||||
|
exec sp_NDrefrenceValue 'GB1202', '2019-05-1 00:00:00.000',0,0,0
|
||||||
|
exec sp_NDrefrenceValue 'GB1203', '2019-05-1 00:00:00.000',0,0,0
|
||||||
|
exec sp_NDrefrenceValue 'GB1204', '2019-05-1 00:00:00.000',0,0,0
|
||||||
|
exec sp_NDrefrenceValue 'GB1205', '2019-05-1 00:00:00.000',0,0,0
|
||||||
|
exec sp_NDrefrenceValue 'GB1206', '2019-05-1 00:00:00.000',0,0,0
|
||||||
|
|
||||||
|
```
|
||||||
|
commit
|
||||||
8
实践积累/数据库/无日志文件附加数据库失败解决.md
Executable file
8
实践积累/数据库/无日志文件附加数据库失败解决.md
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
## 第一步:先建立一个同名数据库,停止SQL SERVER200**==8****,将原来的.mdf****数据库文件****覆盖刚新建的.mdf****数据库文件**==,重新启动数据库第二步:查询分析器执行,
|
||||||
|
|
||||||
|
| | |
|
||||||
|
|---|---|
|
||||||
|
|1 <br>2 <br>3 <br>4 <br>5 <br>6 <br>7|**alter** **database** NEWDBNAME **set** emergency <br>**declare** @databasename **varchar**(255) <br>**set** @databasename='NEWDBNAME' <br>**exec** sp_dboption @databasename, N'single', N'true' <br>dbcc checkdb(@databasename,REPAIR_ALLOW_DATA_LOSS) --将目标数据库置为单用户状态 <br>dbcc checkdb(@databasename,REPAIR_REBUILD) <br>**exec** sp_dboption @databasename, N'single', N'false'|
|
||||||
|
|
||||||
|
## 第三步:以上代码请同时运行,可能会出现“数据库其他多个文件与数据库主文件不匹配....”错误,请多次重试执行以上代码 。
|
||||||
|
> 来自 <[https://zhidao.baidu.com/question/1754918389526048868.html?qbl=relate_question_0&word=sql2008%C8%D5%D6%BE%CE%C4%BC%FE%D3%EB%D6%F7%CE%C4%BC%FE%B2%BB%C6%A5%C5%E4](https://zhidao.baidu.com/question/1754918389526048868.html?qbl=relate_question_0&word=sql2008%C8%D5%D6%BE%CE%C4%BC%FE%D3%EB%D6%F7%CE%C4%BC%FE%B2%BB%C6%A5%C5%E4)>
|
||||||
58
实践积累/数据库/松滋 2号店循环造rtk.md
Executable file
58
实践积累/数据库/松滋 2号店循环造rtk.md
Executable file
@@ -0,0 +1,58 @@
|
|||||||
|
rollback
|
||||||
|
commit
|
||||||
|
begin tran
|
||||||
|
|
||||||
|
```sql
|
||||||
|
declare @x numeric(18,2) --X
|
||||||
|
declare @dt datetime --时间
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
declare @count int --计数
|
||||||
|
|
||||||
|
set @x = 0
|
||||||
|
set @count = 1
|
||||||
|
set @dt = '2018-09-01 18:35:00'
|
||||||
|
|
||||||
|
```
|
||||||
|
while(@dt < getdate()) begin
|
||||||
|
|
||||||
|
-- set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt)
|
||||||
|
|
||||||
|
|
||||||
|
```sql
|
||||||
|
declare @SELECT_SQL1 NVARCHAR(500)
|
||||||
|
declare @GPSINDEX1 bigint
|
||||||
|
declare @utcnow1 datetime
|
||||||
|
declare @adatetime1 datetime
|
||||||
|
declare @X1 float
|
||||||
|
declare @Y1 float
|
||||||
|
declare @H1 float
|
||||||
|
declare @DX1 float
|
||||||
|
declare @DY1 float
|
||||||
|
declare @DH1 float
|
||||||
|
|
||||||
|
SET @SELECT_SQL1 = 'SELECT TOP 1 @X1=T.[X],@Y1 = T.[Y],@H1=T.[Height],@DX1=T.[dltaX],@DY1=T.[dltaY],@DH1=T.[dltaH] FROM [HMProject].[dbo].[SongZi2_RTK] AS T order by ADATETIME desc'
|
||||||
|
|
||||||
|
EXEC sp_executesql @SELECT_SQL1, N'@X1 float out,@Y1 float out,@H1 float out,@DX1 float out,@DY1 float out,@DH1 float out',@X1 out,@Y1 out,@H1 out,@DX1 out,@DY1 out,@DH1 out
|
||||||
|
|
||||||
|
SET @utcnow1 = GETDATE()
|
||||||
|
SET @GPSINDEX1 = (cast(datediff(ss,'1970-01-01',@dt) as bigint)*1000) - ((DateName(minute,@utcnow1))%10)*60000 - DateName(second,@utcnow1)*1000
|
||||||
|
SET @X1 = @X1+ (rand()*-1 + 0.501)/2000 SET @Y1 = @Y1+ (rand()*-1 + 0.501)/2000 SET @H1 = @H1+ (rand()*-1 + 0.499)/2000 SET @DX1 = @DX1+ rand()/99 SET @DY1 = @DY1+ rand()/99 SET @DH1 =
|
||||||
|
|
||||||
|
```
|
||||||
|
@DH1+ rand()/99
|
||||||
|
```sql
|
||||||
|
SET @adatetime1 = DATEADD(S,@GPSINDEX1/1000,'1970-01-01 00:00:00')
|
||||||
|
|
||||||
|
BEGIN TRY insert into [HMProject].[dbo].[SongZi2_RTK]([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])VALUES(@GPSINDEX1,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1) END TRY BEGIN
|
||||||
|
|
||||||
|
```
|
||||||
|
CATCH END CATCH
|
||||||
|
|
||||||
|
--insert into [ZHDMTProj].[dbo].[Flowmeter01]([GPSIndex],[aDatetime],[X]) values(@gpsindex, @dt, @x) --目标表
|
||||||
|
--****************
|
||||||
|
```sql
|
||||||
|
set @count = @count + 1
|
||||||
|
set @dt = DATEADD(MI,5,@dt) --每次递增5 min
|
||||||
|
```
|
||||||
|
end
|
||||||
51
实践积累/数据库/模拟一段数据.md
Executable file
51
实践积累/数据库/模拟一段数据.md
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
```sql
|
||||||
|
declare @dt datetime --时间
|
||||||
|
declare @gpsindex numeric(18,2) --GPSIndex
|
||||||
|
declare @rand float --随机数
|
||||||
|
declare @count int --计数
|
||||||
|
```
|
||||||
|
--declare @GPSINDEX1 bigint
|
||||||
|
```sql
|
||||||
|
declare @adatetime1 datetime
|
||||||
|
declare @endDate datetime; --结束时间
|
||||||
|
declare @X1 float
|
||||||
|
declare @Y1 float
|
||||||
|
declare @H1 float
|
||||||
|
declare @DX1 float
|
||||||
|
declare @DY1 float
|
||||||
|
declare @DH1 float
|
||||||
|
declare @X0 float
|
||||||
|
declare @Y0 float
|
||||||
|
declare @H0 float
|
||||||
|
|
||||||
|
set @dt = '2018-10-23 03:08:00.000';
|
||||||
|
set @endDate= '2018-11-20 18:19:00.000';
|
||||||
|
select @X1 = X,@Y1 = Y,@H1 = Height,@DX1=dltaX,@DY1=dltaY,@DH1=dltaH from MYB1_RTK where aDatetime = @dt
|
||||||
|
```
|
||||||
|
--求出基准坐标
|
||||||
|
```sql
|
||||||
|
set @X0=@X1-@DX1
|
||||||
|
set @Y0=@Y1-@DY1
|
||||||
|
set @H0=@H1-@DH1
|
||||||
|
select @X0,@Y0,@H0
|
||||||
|
```
|
||||||
|
while(@dt < @endDate) begin
|
||||||
|
|
||||||
|
```sql
|
||||||
|
set @gpsindex = convert(bigint, datediff(ss, '1970-01-01 00:00:00', @dt))*1000 + datepart(ms,@dt) SET @DX1 = (rand()*-10 + 10)/2000
|
||||||
|
SET @DY1 = (rand()*-10 + 9)/2000
|
||||||
|
SET @DH1 =(rand()*-10 + 8)/2000
|
||||||
|
SET @X1 = @X0+ @DX1
|
||||||
|
SET @Y1 = @Y0+ @DY1
|
||||||
|
SET @H1 = @H1+ @DH1
|
||||||
|
SET @adatetime1 = DATEADD(S,@gpsindex/1000,'1970-01-01 00:00:00')
|
||||||
|
BEGIN TRY insert into HiMonitorDb.[dbo].MYB1_RTK([GPSIndex],[aDatetime],[X],[Y],[Height],[dltaX],[dltaY],[dltaH])VALUES(@gpsindex,@adatetime1,@X1,@Y1,@H1,@DX1,@DY1,@DH1)
|
||||||
|
END TRY BEGIN
|
||||||
|
```
|
||||||
|
CATCH END CATCH
|
||||||
|
--****************
|
||||||
|
```sql
|
||||||
|
set @count = @count + 1
|
||||||
|
set @dt = DATEADD(MINUTE,5,@dt) --每次递增5min
|
||||||
|
```
|
||||||
|
end
|
||||||
22
实践积累/数据库/解除数据库占用连接.md
Executable file
22
实践积累/数据库/解除数据库占用连接.md
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
use master
|
||||||
|
```sql
|
||||||
|
declare @spid int ;
|
||||||
|
declare @ddlstring nvarchar(max);
|
||||||
|
declare @dbname varchar(200);
|
||||||
|
set @dbname='数据库名';
|
||||||
|
declare tmpcur cursor
|
||||||
|
for select distinct spid as spid from sys.sysprocesses
|
||||||
|
where dbid=db_id(@dbname) ;
|
||||||
|
OPEN tmpcur;
|
||||||
|
fetch tmpcur into @spid ;
|
||||||
|
while (@@FETCH_STATUS=0)
|
||||||
|
```
|
||||||
|
begin
|
||||||
|
```sql
|
||||||
|
set @ddlstring=N'Kill '+CONVERT( nvarchar,@spid) ;
|
||||||
|
execute sp_executesql @ddlstring ;
|
||||||
|
fetch tmpcur into @spid ;
|
||||||
|
end ;
|
||||||
|
```
|
||||||
|
close tmpcur ;
|
||||||
|
deallocate tmpcur ;
|
||||||
43
实践积累/数据库/运行中数据库收缩脚本.md
Executable file
43
实践积累/数据库/运行中数据库收缩脚本.md
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
use master
|
||||||
|
go
|
||||||
|
|
||||||
|
```sql
|
||||||
|
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
|
||||||
|
drop procedure [dbo].[p_killspid]
|
||||||
|
GO
|
||||||
|
|
||||||
|
create proc p_killspid
|
||||||
|
```
|
||||||
|
@dbname varchar(200) --要关闭进程的数据库名
|
||||||
|
as
|
||||||
|
```sql
|
||||||
|
declare @sql nvarchar(500)
|
||||||
|
declare @spid nvarchar(20)
|
||||||
|
|
||||||
|
declare #tb cursor for
|
||||||
|
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
|
||||||
|
open #tb
|
||||||
|
fetch next from #tb into @spid
|
||||||
|
while @@fetch_status=0
|
||||||
|
```
|
||||||
|
begin
|
||||||
|
exec('kill '+@spid)
|
||||||
|
```sql
|
||||||
|
fetch next from #tb into @spid
|
||||||
|
```
|
||||||
|
end
|
||||||
|
close #tb
|
||||||
|
deallocate #tb
|
||||||
|
go
|
||||||
|
|
||||||
|
--用法
|
||||||
|
```sql
|
||||||
|
exec p_killspid 'safeMonitorMgr'
|
||||||
|
go
|
||||||
|
```
|
||||||
|
DBCC SHRINKDATABASE (safeMonitorMgr)
|
||||||
|
go
|
||||||
|
|
||||||
|
```sql
|
||||||
|
drop proc p_killspid
|
||||||
|
```
|
||||||
1
实践积累/数据库/链接服务器远程查询.md
Executable file
1
实践积累/数据库/链接服务器远程查询.md
Executable file
@@ -0,0 +1 @@
|
|||||||
|
>
|
||||||
3
实践积累/数据库/附加数据库.md
Executable file
3
实践积累/数据库/附加数据库.md
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
```sql
|
||||||
|
exec sp_attach_single_file_db @dbname='ZHDMTProj_SX',@physname='F:\DataBases\ZHDMTProj_SX.mdf'
|
||||||
|
```
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user