Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Relationship Diagram

Author  Topic 

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-15 : 13:57:14
Is there a sp or T-SQL command to dynamically build a relationship diagram based on the PK-FK constraints?

I have built a database upgrade script to fix some database design flaws in the original design. I have created the script using test data so that I can eventually apply the script to production data, building a new database with the corrected design. After verifying that everything looks OK in the new design, I will move tables, sp, etc. over to the production database. All of this after I have obviously backed up the production data. I was hoping to build into the script a way to create the relationship diagram in the new database when I run the script.


Jeremy
Jeremy

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-15 : 14:19:33
Man, you'd THINK there'd be something to do that, but I cannot find it in Books Online!

The closest I came was the SQL-NS object model, there are some internal references to database diagrams, but they are not publicly exposed interfaces so they don't seem to be able to be programmed.

The actual diagram info is in the dt_properties table, but it's in an image column, and since you need to build a new diagram you can't just copy it over.

Just out of curiosity, is the EM diagram really used a lot? It always seemed like an ornamental thing IMHO. If I ever needed a real diagram I always used Visio to create or generate one for me.

Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-05-15 : 14:40:13
Only use I really have for it is if the client ever wants someone else to do some work for her or there is a emergency and I can't be reached, then the a developer not familiar with the DB can view the diagram to get the structure.

If there is not obvious way to do this dynamically, then I guess I can take the three extra minutes after the conversion to go through the enterprise manager wizard and let it build the diagram for me. I always thought you could do anything in SQL that you could do in EM, but I guess that is not the case for diagrams.

Thanks robvolk. If you every come accross anything, please let me know. I knew when I posted this, that you would probably respond, because I have seen you respond to other posters on relationship diagrams.

Jeremy

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-15 : 14:51:46


If you're a code hacker, I'm pretty sure there's a way to do it...after all, you're right, EM can do it...it's gotta be some kind of API call.

The only other suggestion I have to to go through the SQL-DMO and SQL-NS object models and all the methods. I gave them a cursory glance but couldn't find anything obvious.

Worst case scenario, and again you'd have to be a monster code hacker, is to invoke the diagram wizard and use SendKeys, or Windows API calls, to have it create the diagram. It's the same as doing it by hand, only automated. I think you'd also have to run EM too, so this is probably too complicated to be practical.

(Just in case you're wondering why I'd even THINK of the last part, I had to do shit like that in my old job! Mr. Femenella (mfemenel) even managed to use SendKeys to automate Lotus cc:Mail this way...which, 4 years later, still impresses me no end! If you can imagine automating a game of FreeCell you'll have an appreciation for the achievement that represents...it's possible, but HARD!)

Go to Top of Page
   

- Advertisement -