如何使用 Visual Studio 数据库项目更改文件路径?

问题描述 投票:0回答:0
declare @databasename varchar(50) = 'aDatabase'
declare @dbNameTimeStamp varchar(100) = 'aDatabase_20230404_0916'

declare @backupFilePathForDev varchar(max) = 'N''J:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\'
declare @backupFilePathForProd varchar(max) = 'N''K:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\'

declare @backupFilePath varchar(max) = 'N''?:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\'
print('backup database ' + @databasename)
exec('BACKUP DATABASE [' + @databasename + '] TO  DISK = ' + @backupFilePath + @dbNameTimeStamp + '.bak'' WITH NOFORMAT, NOINIT,  NAME = N'''+ @databasename + '-Full Database Backup'', SKIP, NOREWIND, NOUNLOAD,  STATS = 10')
insert into MaintenancedFile([filename], filetype, maintenancetype, backuptimestamp)
values(@databasename, 'db', 'backup', GETDATE())

@backupFilePath
的路径因我部署到哪个服务器而不同

是否有一些方法可以根据我通过 Visual Studio 数据库项目使用的发布配置文件更改路径?

sql sql-server visual-studio tsql database-project
© www.soinside.com 2019 - 2024. All rights reserved.