简体   繁体   English

SQL 服务器错误“操作数类型冲突:varchar 与 int 不兼容”

[英]SQL Server error "Operand type clash: varchar is incompatible with int "

I have made below stored procedure for taking the backup of a database我已经制作了以下用于备份数据库的存储过程

CREATE PROCEDURE [dbo].[usp_databasebackup]  
    @DatabaseName NVARCHAR(200),
    @Path NVARCHAR(500)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @sqlQuery  VARCHAR(5000)  

    BEGIN
        SET @sqlQuery = ' BACKUP DATABASE ['+@DatabaseName+'] TO DISK = N''D:\@DatabaseName.bak'' 
                          WITH COPY_ONLY, NOFORMAT, NOINIT, NAME = N''@DatabaseName-Full Database Backup'', 
                          SKIP, NOREWIND, NOUNLOAD, STATS =''10'' '

        EXEC (@sqlQuery)
    END
END
GO

When I execute the stored procedure with a database name and path as parameters, I get this error:当我使用数据库名称和路径作为参数执行存储过程时,出现此错误:

Operand type clash: varchar is incompatible with int操作数类型冲突:varchar 与 int 不兼容

You can backup a database without using Dynamic SQL.您可以在不使用动态 SQL 的情况下备份数据库。

You just need to use the backup command like this你只需要像这样使用备份命令

backup database @DatabaseName
to disk=@DiskName
with name=@Name,
compression, format, init, skip, norewind, nounload, stats=10

@DatabaseName should be sysname @DatabaseName应该是sysname

You need to prepare / concatenate names and paths prior to using variables in the backup command - ie, @DiskName would be a concatenation of a path and filename with a ".bak" suffix.在备份命令中使用变量之前,您需要准备/连接名称和路径 - 即, @DiskName将是带有“.bak”后缀的pathfilename的连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL 服务器“操作数类型冲突:int 与日期不兼容”错误 - SQL Server 'Operand type clash: int is incompatible with date' error SQL Server-与工会的错误“操作数类型冲突uniqueidentifier与int不兼容” - SQL Server - error 'operand type clash uniqueidentifier is incompatible with int' with Union SQL 服务器错误操作数类型冲突:int 与日期不兼容 - SQL Server error Operand type clash: int is incompatible with date SQL Server 2012(触发器)操作数类型冲突:int与日期不兼容 - SQL Server 2012 (triggers) Operand type clash: int is incompatible with date SQL Server:返回的UniqueIdentifier,操作数类型冲突:uniqueidentifier与int不兼容 - SQL Server: Returning UniqueIdentifier, Operand type clash: uniqueidentifier is incompatible with int SQL-Server - 操作数类型冲突:uniqueidentifier与int不兼容 - SQL-Server - Operand type clash: uniqueidentifier is incompatible with int SQL Server Operand类型冲突:日期与int不兼容 - Sql Server Operand type clash: date is incompatible with int SQL错误IS操作数类型冲突:int与日期不兼容 - SQL ERROR IS Operand type clash: int is incompatible with date SQL Server 错误 - 操作数类型冲突:ntext 与 int 不兼容 -(我什至没有使用“ntext”) - SQL Server error - Operand type clash: ntext is incompatible with int - (I'm not even using "ntext") 操作数类型冲突:int 与日期错误不兼容 - Operand type clash: int is incompatible with date error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM