Book a Demo

Author Topic: How to Generate DDL with Foreign Keys  (Read 6220 times)

Taz

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
  • Imagine, sun, beach and financial freedom
    • View Profile
How to Generate DDL with Foreign Keys
« on: March 13, 2008, 03:34:04 am »
We created a data schema and generated the ddl for SQL Server 2005, but it seemed to miss the Foreign Keys.  Did we miss something. We clicked the Primary/Foreign Key Constraints in the "Generate Package DDL" dialog. The Primay Keys Constraints were created but not the Foreign Keys.  

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to Generate DDL with Foreign Keys
« Reply #1 on: March 13, 2008, 07:07:48 am »
Taz,

That seems very odd to me. I've been able to do this in the past. But I've not tried it for some time. In fact, I may have imported the DDL from SQL Server 2000 only (rather than 2005).

What build of EA are you using? And what provider did you use to connect to the database?

David
No, you can't have it!

Taz

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
  • Imagine, sun, beach and financial freedom
    • View Profile
Re: How to Generate DDL with Foreign Keys
« Reply #2 on: March 13, 2008, 10:35:33 pm »
Hi David,

Thanks for your reply.  We are using SQL Server 2005 and EA 7.1 (Build 827) and only have generated the Scripts so far which don't show the Foreign Key Constraints.

Taz
« Last Edit: March 13, 2008, 10:38:29 pm by Taz »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to Generate DDL with Foreign Keys
« Reply #3 on: March 13, 2008, 11:32:38 pm »
And did you make sure you created the foreign keys the way Sparx describes it? [Create an association, right-click on it, and choose Foreign Keys from the context menu to bring up the correct dialog.]

=====

EDIT: I just created a new project with build 827 - just to be sure - and my default DBMS set to SQL Server 2005.

The good news: EA generated the foreign key constraint correctly.

The bad news: My first attempt to populate a data model diagram caused EA to crash when I added the first table. I have not yet been able to duplicate the problem.

David
« Last Edit: March 13, 2008, 11:42:02 pm by Midnight »
No, you can't have it!

Taz

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
  • Imagine, sun, beach and financial freedom
    • View Profile
Re: How to Generate DDL with Foreign Keys
« Reply #4 on: March 14, 2008, 12:12:09 am »
You're right, we missed that step.  What confused us was, that the diagram shows a FK constrained when you link two tables making us believe, that constrained was already created. When generating the code, it also dropped that FK constrained, but then didn't recreate it.

Thanks for your help.


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: How to Generate DDL with Foreign Keys
« Reply #5 on: March 14, 2008, 02:03:56 am »
This seems to be one of those things that EA does in its own way. The documentation does warn you not to try this yourself but to use the dialog. The strange thing is that you can do it yourself, and the results can look pretty good, but EA may act rather unpredictably.

A word to the wise: this can make things very difficult if you are writing the models through automation.

David
No, you can't have it!