SQL 服务器:'DUMP' 附近的语法不正确
SQL Server: Incorrect syntax near 'DUMP'
我有以下存储过程在 SQL Server 2008 R2 和 2016 中创建数据库转储,这些存储过程已经存在于数据库中,我正在将它们移动到不同的数据库
PRINT N'Creating [dbo].[sp_univ_backupDB]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure [dbo].[sp_univ_backupDB]
/*****************************************************************
* This proc is scheduled to run daily and creates a full database
* backup of the following databases
*
* Database Device
* --------- -----------
* Einvapp einv_daily
* Master mst_daily
*
*****************************************************************/
AS
DUMP DATABASE master TO mst_daily WITH INIT, SKIP
DUMP DATABASE einvapp TO einv_daily WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[sp_univ_backupMSDB]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Procedure [dbo].[sp_univ_backupMSDB]
/*****************************************************************
* This proc is scheduled to run daily and creates a full database
* backup of the following databases
*
* Database Device
* --------- -----------
* msdb msdb_daily
*
*
*
*
*****************************************************************/
AS
DUMP DATABASE msdb TO msdb_daily WITH INIT, SKIP
DUMP DATABASE arceapp TO arceapp_daily WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[sp_univ_backupTran]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[sp_univ_backupTran]
/*****************************************************************
* This proc is scheduled to run hourly and creates a full transaction
* log backup of the following databases
*
* Database Device
* --------- -----------
* einvapp
* Master
*
*****************************************************************/
AS
DECLARE @Hour CHAR(4),
@DiskDev VARCHAR(20)
SELECT @hour = Right(+'00' + RTRIM(CONVERT(char(2),DATEPART(hour,GETDATE()))) +'00',4)
SELECT @DiskDev = (SELECT CASE @HOUR
WHEN '0500' THEN 'tran_0500'
WHEN '0600' THEN 'tran_0600'
WHEN '0700' THEN 'tran_0700'
WHEN '0800' THEN 'tran_0800'
WHEN '0900' THEN 'tran_0900'
WHEN '1000' THEN 'tran_1000'
WHEN '1100' THEN 'tran_1100'
WHEN '1200' THEN 'tran_1200'
WHEN '1300' THEN 'tran_1300'
WHEN '1400' THEN 'tran_1400'
WHEN '1500' THEN 'tran_1500'
WHEN '1600' THEN 'tran_1600'
WHEN '1700' THEN 'tran_1700'
WHEN '1800' THEN 'tran_1800'
WHEN '1900' THEN 'tran_1900'
ELSE 'NONE'
END)
IF @diskDev <> 'NONE'
DUMP TRANSACTION einvapp TO @diskDev WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
当我 运行 上面的脚本在 SQL Server 2008 R2 和 2016 中都失败并出现以下错误:
Msg 102, Level 15, State 1, Procedure sp_univ_backupDB, Line 25
Incorrect syntax near 'DUMP'.
Msg 319, Level 15, State 1, Procedure sp_univ_backupDB, Line 25
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Procedure sp_univ_backupMSDB, Line 22
Incorrect syntax near 'DUMP'.
Msg 319, Level 15, State 1, Procedure sp_univ_backupMSDB, Line 22
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Procedure sp_univ_backupTran, Line 50
Incorrect syntax near 'DUMP'.
Msg 319, Level 15, State 1, Procedure sp_univ_backupDB, Line 26
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
谁能帮我解决这个问题SQL?
我发现了一些讨论此问题的线程,但使用时间比我在 SQL 服务器上的时间早了很多。看来这是 BACKUP 之前使用的命令;我找不到任何详细说明它们有何不同的网站。
使用 sys.backup_devices
目录视图检查原始数据库中这些逻辑设备的位置。
SQL 服务器中没有 DUMP
命令。但是,如果您将 DUMP
替换为 BACKUP
用于数据库备份,将 BACKUP LOG
替换为事务备份,并且您在新数据库中定义了逻辑备份设备,脚本将正常工作。
我有以下存储过程在 SQL Server 2008 R2 和 2016 中创建数据库转储,这些存储过程已经存在于数据库中,我正在将它们移动到不同的数据库
PRINT N'Creating [dbo].[sp_univ_backupDB]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure [dbo].[sp_univ_backupDB]
/*****************************************************************
* This proc is scheduled to run daily and creates a full database
* backup of the following databases
*
* Database Device
* --------- -----------
* Einvapp einv_daily
* Master mst_daily
*
*****************************************************************/
AS
DUMP DATABASE master TO mst_daily WITH INIT, SKIP
DUMP DATABASE einvapp TO einv_daily WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[sp_univ_backupMSDB]'
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE Procedure [dbo].[sp_univ_backupMSDB]
/*****************************************************************
* This proc is scheduled to run daily and creates a full database
* backup of the following databases
*
* Database Device
* --------- -----------
* msdb msdb_daily
*
*
*
*
*****************************************************************/
AS
DUMP DATABASE msdb TO msdb_daily WITH INIT, SKIP
DUMP DATABASE arceapp TO arceapp_daily WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
PRINT N'Creating [dbo].[sp_univ_backupTran]'
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[sp_univ_backupTran]
/*****************************************************************
* This proc is scheduled to run hourly and creates a full transaction
* log backup of the following databases
*
* Database Device
* --------- -----------
* einvapp
* Master
*
*****************************************************************/
AS
DECLARE @Hour CHAR(4),
@DiskDev VARCHAR(20)
SELECT @hour = Right(+'00' + RTRIM(CONVERT(char(2),DATEPART(hour,GETDATE()))) +'00',4)
SELECT @DiskDev = (SELECT CASE @HOUR
WHEN '0500' THEN 'tran_0500'
WHEN '0600' THEN 'tran_0600'
WHEN '0700' THEN 'tran_0700'
WHEN '0800' THEN 'tran_0800'
WHEN '0900' THEN 'tran_0900'
WHEN '1000' THEN 'tran_1000'
WHEN '1100' THEN 'tran_1100'
WHEN '1200' THEN 'tran_1200'
WHEN '1300' THEN 'tran_1300'
WHEN '1400' THEN 'tran_1400'
WHEN '1500' THEN 'tran_1500'
WHEN '1600' THEN 'tran_1600'
WHEN '1700' THEN 'tran_1700'
WHEN '1800' THEN 'tran_1800'
WHEN '1900' THEN 'tran_1900'
ELSE 'NONE'
END)
IF @diskDev <> 'NONE'
DUMP TRANSACTION einvapp TO @diskDev WITH INIT, SKIP
GO
IF @@ERROR <> 0 SET NOEXEC ON
GO
当我 运行 上面的脚本在 SQL Server 2008 R2 和 2016 中都失败并出现以下错误:
Msg 102, Level 15, State 1, Procedure sp_univ_backupDB, Line 25
Incorrect syntax near 'DUMP'.Msg 319, Level 15, State 1, Procedure sp_univ_backupDB, Line 25
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.Msg 102, Level 15, State 1, Procedure sp_univ_backupMSDB, Line 22
Incorrect syntax near 'DUMP'.Msg 319, Level 15, State 1, Procedure sp_univ_backupMSDB, Line 22
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.Msg 102, Level 15, State 1, Procedure sp_univ_backupTran, Line 50
Incorrect syntax near 'DUMP'.Msg 319, Level 15, State 1, Procedure sp_univ_backupDB, Line 26
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
谁能帮我解决这个问题SQL?
我发现了一些讨论此问题的线程,但使用时间比我在 SQL 服务器上的时间早了很多。看来这是 BACKUP 之前使用的命令;我找不到任何详细说明它们有何不同的网站。
使用 sys.backup_devices
目录视图检查原始数据库中这些逻辑设备的位置。
SQL 服务器中没有 DUMP
命令。但是,如果您将 DUMP
替换为 BACKUP
用于数据库备份,将 BACKUP LOG
替换为事务备份,并且您在新数据库中定义了逻辑备份设备,脚本将正常工作。