Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQL Server中,如何将一列从一个表复制到另一个表_Sql_Sql Server_Transactions_Sql Server 2008 R2 - Fatal编程技术网

在SQL Server中,如何将一列从一个表复制到另一个表

在SQL Server中,如何将一列从一个表复制到另一个表,sql,sql-server,transactions,sql-server-2008-r2,Sql,Sql Server,Transactions,Sql Server 2008 R2,我使用SQLServer2008R2,我的问题是一个名为LogStats的数据库 如果执行此查询: select * from ExceptionRow inner join HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5 where ExceptionRow.Message is null AND not HashFP.MessageFP is null 我有126708支安打,需要2.05分钟。但优化不是我的问题

我使用SQLServer2008R2,我的问题是一个名为LogStats的数据库

如果执行此查询:

select *
from ExceptionRow
     inner join HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
where ExceptionRow.Message is null
      AND not HashFP.MessageFP is null 
我有126708支安打,需要2.05分钟。但优化不是我的问题

我想将数据从HashFP.MessageFP复制到ExceptionRow.Message,而不覆盖任何数据。我试试这个:

UPDATE ExceptionRow
SET Exceptionrow.Message = HashFP.MessageFP
FROM ExceptionRow 
     INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL
      AND NOT HashFP.MessageFP IS NULL
结果是:

Msg 9002,17级,状态4,第1行数据库的事务日志 “LogStats”已满。要了解日志中的空间无法重用的原因, 请参阅sys.databases中的log\u reuse\u wait\u desc列

我试过这个:

SELECT name,log_reuse_wait_desc FROM sys.databases
从结果来看

tempdb   ACTIVE_TRANSACTION
LogStats ACTIVE_TRANSACTION
如何中止这些活动事务以使任务成功

UPDATE ExceptionRow SET Exceptionrow.Message = HashFP.MessageFP FROM ExceptionRow 
INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL AND HashFP.MessageFP IS NOT NULL

由于您将使用HashFP.MessageFP在null时更新ExceptionRow.Message,因此无需担心HashFP.MessageFP中是否包含null

由于您将使用HashFP.MessageFP在null时更新ExceptionRow.Message,因此无需担心HashFP.MessageFP中是否包含null

如何中止这些活动事务以使任务成功

UPDATE ExceptionRow SET Exceptionrow.Message = HashFP.MessageFP FROM ExceptionRow 
INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL AND HashFP.MessageFP IS NOT NULL
您不能,因为这是来自事务的
更新
您可以增加日志文件的最大大小:

ALTER DATABASE DB_NAME
MODIFY FILE (NAME=LOG_FILE_NAME,MAXSIZE=UNLIMITED);
或者您可以尝试以下方法:

WHILE EXISTS
(select *
from ExceptionRow
     inner join HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
where ExceptionRow.Message is null
      AND not HashFP.MessageFP is null
)
UPDATE TOP (1000) ExceptionRow
SET Exceptionrow.Message = HashFP.MessageFP
FROM ExceptionRow 
     INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL
      AND NOT HashFP.MessageFP IS NULL
如果数据库有简单的恢复模型,这应该可以工作,如果完全或大容量加载,您还需要在每次迭代中备份事务日志

如何中止这些活动事务以使任务成功

UPDATE ExceptionRow SET Exceptionrow.Message = HashFP.MessageFP FROM ExceptionRow 
INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL AND HashFP.MessageFP IS NOT NULL
您不能,因为这是来自
事务的
更新
您可以增加日志文件的最大大小:

ALTER DATABASE DB_NAME
MODIFY FILE (NAME=LOG_FILE_NAME,MAXSIZE=UNLIMITED);
或者您可以尝试以下方法:

WHILE EXISTS
(select *
from ExceptionRow
     inner join HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
where ExceptionRow.Message is null
      AND not HashFP.MessageFP is null
)
UPDATE TOP (1000) ExceptionRow
SET Exceptionrow.Message = HashFP.MessageFP
FROM ExceptionRow 
     INNER JOIN HashFP ON ExceptionRow.Hash=HashFP.FingerPrintMD5
WHERE ExceptionRow.Message IS NULL
      AND NOT HashFP.MessageFP IS NULL
如果数据库有简单的恢复模型,这应该可以工作,如果完全或大容量加载,您还需要在每次迭代中备份事务日志