我想同时使用python和SQL还原SQL数据库。但是我不知道如何在我的sql脚本中调用数据库名称。这是我下面使用的代码(==> %BackupClean ),但是它不起作用。我无法在SQL脚本中插入BackupClean变量。有谁知道我该怎么办?谢谢您的帮助
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
from dataiku.core.sql import SQLExecutor2
# Read recipe inputs
backups = dataiku.Dataset("backups")
backups_df = backups.get_dataframe()
backupName_df = backups_df
BackupClean = backupName_df.Name[1].replace('.BAK' ,'')
print(BackupClean)
executor = SQLExecutor2(connection="FR0010APP35")
tableSQL_df = executor.query_to_df("""
RESTORE DATABASE %s;""" %BackupClean
""" FROM DISK = N'C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\Backups-
dss\database_db_201502120000.BAK'
WITH FILE = 1,
MOVE N'V473TEMPMLG_Data' TO N'C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\database_Data.MDF',
MOVE N'V473TEMPMLG_Log' TO N'C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\database_Log.LDF',
NOUNLOAD, STATS = 5 """)
# Write recipe outputs
backupName = dataiku.Dataset("BackupName")
backupName.write_with_schema(backupName_df)
我需要检索此名称,因为之后将进行循环。