I have scripts running on first database but I want to create schema on other database. Specifically, I'm running this script:
DECLARE @USE_TEMPLATE VARCHAR(MAX) SET @USE_TEMPLATE = 'USE
[{DBNAME}]'
DECLARE @DatabaseName nvarchar(50); DECLARE @HistDatabaseName
nvarchar(50);
SET @DatabaseName = DB_NAME(); SET @HistDatabaseName = @DatabaseName +
N'_Audit'
DECLARE @SQL_SCRIPT VARCHAR(MAX)
SET @SQL_SCRIPT = REPLACE(@USE_TEMPLATE, '{DBNAME}',
@HistDatabaseName) EXECUTE (@SQL_SCRIPT)
DECLARE @schemaTSQL varchar(100) = 'CREATE SCHEMA [newschema]
AUTHORIZATION [dbo];' EXECUTE (@schemaTSQL);
If I hardcode database name it works, but I want this script to be used in EF migrations. For example, this works:
USE [SecondDatabase]
DECLARE @schemaTSQL varchar(100) = 'CREATE SCHEMA [newschema]
AUTHORIZATION [dbo];' EXECUTE (@schemaTSQL);
Aucun commentaire:
Enregistrer un commentaire