Welcome to ModelRight Sign in | Join | Help
in

Create constraints without creating table

Last post 05-08-2008, 11:14 AM by footndale. 3 replies.
Sort Posts: Previous Next
  •  05-06-2008, 2:06 PM 631

    Create constraints without creating table

    It you be nice to generate constraint DDL, with out also creating the table ddl.

     

    Also the drop statements for constraints doesn't get created, even if it is selected in the wizard.

  •  05-06-2008, 2:25 PM 632 in reply to 631

    Re: Create constraints without creating table

    Yes, we agree. This is a feature that is on the list for MR4. In meantime, you can use Scripting to do the same thing...

    Please, do the following:

    1.    Go to the Script Explorer.
    2.    Select User Defined
    3.    From the menu context, select New Script
    4.    Name the New Script created as “CreateFKs”, or whatever you like.
    5.    Paste the following:

    Sub Evaluate_OnLoad()
        Set Context = CreateObject("SCF.ScriptContext")
        Set Document = Context.ScriptDocument
        Set ThisScript = Context.Object
        Set Options = Context.Options
        Dim CreateStmt
        Set Model = ThisScript.Model
        Set Tables = Model.AsObject.Children("Table")
        For Each Table In Tables
            Set Relations = Table.Children("Relation")
            For Each Relation in Relations
                CreateStmt = Relation.Evaluate("Create Script")
                Document.Write(CreateStmt & vbNewLine)
            Next
        Next
    End Sub

    6.    Click the Run button in the script property page… you should see all of your Alter FK script that you can copy/paste into a file.

    Easy to repeat for other object types... for instance Indexes:

    Please repeat the same steps as above (at step 4, rename to “CreateIndexes”) and at step 5 paste the following:

    Sub Evaluate_OnLoad()
        Set Context = CreateObject("SCF.ScriptContext")
        Set Document = Context.ScriptDocument
        Set ThisScript = Context.Object
        Set Options = Context.Options
        Dim CreateStmt
        Set Model = ThisScript.Model
        Set Tables = Model.AsObject.Children("Table")
        For Each Table In Tables
            Set Indexes = Table.Children("Index")
            For Each Index in Indexes
                CreateStmt = Index.Evaluate("Create Script")
                Document.Write(CreateStmt & vbNewLine)
            Next
        Next
    End Sub

    Etc....

     Hope this helps.


    ModelRight Evangelist
  •  05-06-2008, 3:40 PM 635 in reply to 632

    Re: Create constraints without creating table

    Also, look under the Download/Other Files/Scripts section for GenerateConstraints and GenerateIndexes scripts that you can use.


    ModelRight Evangelist
  •  05-08-2008, 11:14 AM 637 in reply to 635

    Re: Create constraints without creating table

    Thank you very much.