我需要知道如何重建分区表聚集索引,表大小约为 270 GB,有 126 个分区。
另外,我想在生产环境中执行它,那么最快的方法是什么以及如何执行。
这是一个非常关键的改变,需要完成,因此任何帮助或建议将不胜感激。
我试图弄清楚发生了什么,但目前我无法解决这个问题......
我有两台具有相同规格的服务器,实际上也连接了几乎相同的用户(只有我)...
其中一台服务器的 CPU 使用率稳定在 20%,而另一台服务器的 CPU 使用率稳定在 1%...相同的数据库,相同的进程...
如果 SQL Server 和其他服务器都处于空闲状态,我如何才能知道与其他服务器相比,SQL Server 上实际消耗如此大量 CPU 的是什么?
我想以这样的方式返回数据,即如果代码具有连续的活动日期和结束日期,则数据应给出最小活动日期和最大结束日期,但如果代码已停止,则应显示两个日期
例如桌子
+----+------+---------------+------------+
|Code| Decri| Active Date |End Date |
+----+------+---------------+------------+
|1000| ABC | 1/1/2011 | 30/6/2011 |
|1000| ABC | 1/7/2011 | 30/6/2012 |
|1000| ABC | 1/7/2012 | 30/6/2013 |
|1001| ABC | 1/7/2013 | 30/6/2014 |
|1001| ABC |12/20/2015 |12/20/2017 |
|1003| ABC | 1/1/2011 |30/6/2011 |
|1003| ABC | 1/7/2012 |30/6/2013 |
|1003| ABC | 1/7/2014 |30/6/2015 |
|1003| ABC | 1/7/2015 |12/20/2017 |
+----+------+---------------+------------+
Run Code Online (Sandbox Code Playgroud)
欲望输出
+----+------+---------------+------------+
|Code| Decri| Active Date |End Date |
+----+------+---------------+------------+
|1000| …Run Code Online (Sandbox Code Playgroud) 有没有办法按顺序链接两个表?
表 A(实际):
EX STATUS DLV Actual FEE Expected Fee
N ACT MAIL 1.25
N ACT EMAIL 1.25
N ACT PICKUP 0
N NON MAIL 0
N NON EMAIL 1.25
N NON PICKUP 0
Y 0
Run Code Online (Sandbox Code Playgroud)
表 B(预期):
EX STATUS DLV Expected FEE
N ACT MAIL 1.25
N ACT EMAIL 0
N ACT PICKUP 0
N NON MAIL 1.25
N NON EMAIL 0
N NON PICKUP 0
Y 0
Run Code Online (Sandbox Code Playgroud)
表 A(预期结果):
EX STATUS DLV Actual FEE Expected Fee
N ACT …Run Code Online (Sandbox Code Playgroud) 将 SQL Server 2012 中的参数化选项从“简单”更改为“强制”是否会清除缓存;或者应该在更改后运行 DBCC FREEPROCCACHE?
对于给定的分区方案名称,我需要检索一组
这必须在不存在参与该方案的任何表的情况下起作用。
即通过 sys.indexes 加入将不起作用。
我认为答案在于 sys.destination_data_spaces,但尚未弄清楚与 sys.partition_range_values 的连接。
在这里处于相当不利的位置。今天下午在我的 tempDB 上,我运行了以下查询:
sp_helpfile找到我的 MDF 和 LOG 文件所在的位置。我的 MDF 在我的 C: 驱动器上,而我的 LOG 文件在 D: 驱动器上,所以我运行了以下查询以将此日志文件从 D: 驱动器移回 C: 驱动器。(这可能不是我运行的确切查询,因为我不记得它到底是什么!)
use master
go
Alter database tempdb modify file (name = templog, filename = 'C:[drivelocation]\tempdb.ldf')
go
Run Code Online (Sandbox Code Playgroud)
运行后,我关闭了 SQL Server MS 2012 并重新打开以连接回我机器上的 SQL Server。尝试登录时,SQL MS 返回以下错误:
Run Code Online (Sandbox Code Playgroud)=================================== Cannot connect to machineName\SQL2012. =================================== A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is …
我试图理解read-ahead reading,但对我来说似乎有点复杂。我在网上搜索并得到以下信息:
从阅读页面(微软文档):
预读预期完成查询执行计划所需的数据和索引页,并在查询实际使用这些页之前将它们放入缓冲区缓存。
从对为什么在 SQL Server 中首次执行查询时“物理读取”少于“预读”和“逻辑读取”的回答?作者:huntharo 在 Stack Overflow 上:
物理读取 - 查询被阻塞,等待页面从磁盘读取到缓存中以供立即使用。
Read-Ahead Read - 页面在阻塞查询之前被读取,并像所有读取一样被读入缓存。当您扫描索引时,预读是可能的,在这种情况下,可以假定索引中的下一个叶页是需要的,并且可以在查询实际表示需要它们之前为它们启动读取。这允许磁盘在 db 引擎检查先前获取的页面的内容时忙碌。
也许有人可以使用他们自己的解释来澄清上述内容,因为我找不到预读的详细解释。
举个例子,看看statistics io信息:
Table 'TestLarge'. Scan count 1, logical reads 159185, physical reads 348, read-ahead reads 159209
Run Code Online (Sandbox Code Playgroud) 我感觉这应该是一个很简单的问题。我想要做的就是返回刚刚插入的条目的时间戳,但在同一个调用中。我在搜索中所能找到的只是返回身份列(id)。但我只需要时间戳。这是我的存储过程:
ALTER PROCEDURE [dbo].[insertLabelHistory]
@itemID VARCHAR(50)
,@enterType INT
,@authID INT = NULL
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO LABEL_CHECK_HIST
(ITEM_ID, ENTERED_DATE, ENTER_TYPE, AUTH_ID)
VALUES
(@itemID, CURRENT_TIMESTAMP ,@enterType, @authID)
END
Run Code Online (Sandbox Code Playgroud)
这是在 SQL Server 2012 中。
我有一个存储过程,可以识别上次 SSIS 作业运行中候选人信息的任何更改。然后它继续将更改保存在同步表中。
\nCREATE PROCEDURE [dbo].[IdentifyCandidateChanges]\xc2\xa0\xc2\xa0\n(\xc2\xa0\xc2\xa0\n@MoreToProcess BIT = 0 OUTPUT\xc2\xa0\xc2\xa0\n)\xc2\xa0\xc2\xa0\nAS\xc2\xa0\xc2\xa0\n\nSET NOCOUNT ON\xc2\xa0\xc2\xa0\n\nDECLARE @BatchSize INT\xc2\xa0\xc2\xa0\n\nSELECT\xc2\xa0\xc2\xa0\n@MoreToProcess = 0\xc2\xa0\xc2\xa0\n, @BatchSize = 200000\xc2\xa0\xc2\xa0\n\nDECLARE @Changes TABLE\xc2\xa0\xc2\xa0\n(\xc2\xa0\xc2\xa0\n CandidateNo VARCHAR(10) NOT NULL\xc2\xa0\xc2\xa0\n, CentreNo CHAR(5) NOT NULL\xc2\xa0\xc2\xa0\n, CandidateModifiedDate DATETIME NOT NULL\xc2\xa0\xc2\xa0\n, ChangeStatus CHAR(1) NOT NULL\xc2\xa0\xc2\xa0\n)\xc2\xa0\xc2\xa0\n\n-- If this is the first run (or the CandidateSync table is empty for another reason) then just take the hit now\xc2\xa0\xc2\xa0\n-- and process the entire set of candidates in one go.\xc2\xa0\xc2\xa0\n\nIF EXISTS(SELECT TOP 1 1 FROM CandidateSync)\xc2\xa0\xc2\xa0\nSET ROWCOUNT @BatchSize\xc2\xa0\xc2\xa0\n\nINSERT INTO @Changes\xc2\xa0\xc2\xa0\n(\xc2\xa0\xc2\xa0\n CandidateNo\xc2\xa0\xc2\xa0\n, …Run Code Online (Sandbox Code Playgroud) sql-server-2012 ×10
sql-server ×8
partitioning ×2
buffer-pool ×1
metadata ×1
performance ×1
query ×1
t-sql ×1
tempdb ×1