Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to generate physical database from my logical model using ERWIN 7.

All is well in the script that is generated automatically, there is only the problem that the model is created in the database "master" which is the default SQL Server, rather than being created in the database that I inserted along with the model.

I cant find a way to associate my MODEL with the database I'm creating along with the model.

Here is the script that ERWIN auto-generates:

CREATE DATABASE Movies go
ALTER DATABASE Movies SET  RECOVERY FULL go
CREATE SCHEMA fbd AUTHORIZATION dbo go
CREATE DEFAULT Default_Value_movies_gen   AS 1 go
CREATE DEFAULT Default_Value_titulo_movies    AS 'No title' go

But it should generate automatically:

CREATE DATABASE Movies go 
--Here should be "USE Movies",to use database that ERWIN have just created
ALTER DATABASE Movies SET RECOVERY FULL go
CREATE SCHEMA fbd AUTHORIZATION dbo go
CREATE DEFAULT Default_Value_movies_gen AS 1 go
CREATE DEFAULT Default_Value_titulo_movies AS 'No title' go

Any ideas?

share|improve this question
    
Edit the Database Template and choose your new template for Forward Engineering –  da_didi Apr 17 '14 at 4:10

1 Answer 1

You have to edit the Forward Engineering Template (FE Template).

Simple said, hard done.

As each class of entities (table, views, SPs, etc.) have their own block of generation code, it has to be done to each major entry points.

As for the SQL Server 2005 Erwin's template at its 7.3 version, the code below, injected at the beginning of the 'Create Entity' template will do for table DMLs.

/*

  We will save a global flag '_SQL_USE_DATABASE' is used to flag a variable of the same name initialization */
/

@ifnot( IsGlobalFlagSet("_SQL_USE_DATABASE") )
{
    Set( "_SQL_USE_DATABASE", "")
    SetGlobalFlag( "_SQL_USE_DATABASE" )
}

@if( IsPropertyNotNull("SQLServer_File_Group_Ref") )
{
    PushReference( "SQLServer_File_Group_Ref" )
    PushOwner

    @ifnot( Equal(Value("_SQL_USE_DATABASE"), Property("Name")) )
    {
        FE::Bucket( "90" )
        "USE " Property("Name")
        FE::EndOfStatement

        Set( "_SQL_USE_DATABASE", Property("Name") )
    }

    Pop
    Pop 
}
@else
{
    Set( "_SQL_USE_DATABASE", "" )
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.