Simplifying Database Modeling in Visio 2002/2003 through SQL Generation

By admin on May 10 2007 | 7 Comments
 

During the development of any new greenfield project you're going to probably need to interact with a datastore.
From my experience, 8 out of 10 times this is going to be a database acting as the datastore, and in my case, it's normally SQL Server.

Database Modeling

When in the design phase we're modeling. Creating a representation of what we're going to build. In the design of a database I use Visio to do this by building an ERD Diagram.

If you're like me you're still probably using Visio 2002/2003. If you're also like me, you don't have the Enterprise Architect version of Visio that allows you to forward engineer the database from the ERD Diagram that you've created.

So, therein lies a problem. I have to design my database in Visio, then manually create the SQL and run it in query analyzer to get my database. Seem's like double the work to me.

1. Create the diagram and all the types and relationshiops
2. Copy it by hand into SQL Server Management Studio or the Query Window

I've always felt that Microsoft should have included forward engineering for Visio, regardless of the version. Unfortunately they didnt feel the same way.

Model to SQL

Fortunately there is a solution. A company called Orthogonal Software has a Visio plug-in called Orthogonal Toolbox that will allow you to export the data from the Visio document to an XML File.

Orthogonal has provided a couple XSLT's that you can apply (look for XSLT on that page). One of which has been altered to export SQL.

The XSLT file that originally was found with the product exported the SQL into one long string. No line breaks, nothing. Just a long string. After some futz'n around with the XSLT I was able to format the SQL that was transformed into readable SQL.

For example, a XSLT generated SQL Code that looks like this:

CREATE TABLE dbo.Employee( 
   [Employee_Id] bigint NOT NULL,
   [Name] nvarchar(100) NOT NULL
);
GO

How to implement

1. Download Orthogonal Toolbox and install it.
2. Create your Visio ERD Diagram.
3. Click the Orthogonal Toolbox Button in the toolbar.
4. Export to XML.
5. Put the XSLT files (download at the bottom of this post) into the same file as the XML File.
6. Open the newly created XML File and add this line after the XML Definition.
    <?xml-stylesheet type="text/xsl" href="ERD-SQL2005.xslt"?>
6. Open the XML file in Internet Explorer
7. Copy/Paste what you see into Query Analyzer and run.

Thats it. You've now gone from Database ERD Model to SQL Code in a few quick steps. TONS of time saved.

Update for SQL Server 2005

The original XSLT was for use with SQL Server 2000. Schemas were not supported in 2000, therefore everything started with "dbo". To get around this, I reworked the XSLT and changed it to use the table name.

When I'm designing for a SQL Server 2005 database I'll give my tables names such as [My_Schema].[Table_Name]. Therefore when I export and apply my XSLT, the new exported SQL will look like this:

CREATE TABLE [HumanResources].[Employee]( 
   [Employee_Id] bigint NOT NULL,
   [Name] nvarchar(100) NOT NULL   
);
GO

Where "HumanResources" is the schema and "Employee" is the table name.

 

Downloads

2000and2005XSLTs.zip (2.96 KB)

 

kick it on DotNetKicks.com

Post info

Tags:
Categories: Productivity , SQL Server

Comments

egbsysems
egbsysems on 6/26/2007 9:41 AM <a href="http://www.egbsystems.com"><b>WEB SITE DESIGN AND DEVELOPMENT & SOFTWARE DEVELOPMENT SERVICES</b></a>
EGB Systems & Solutions Inc is an IT company. We have well trained and experienced staff.
We have programmers, software testers and SEO. The working environment is very good.
Our company is a full service <a href= "www.egbsystems.com/.../...te_design.html"> web site design company </a>  providing all services such as website optimization, search engine submissions and promotion.
Our motto is “If you think big, then you can achieve the goal”.

Layout and Design
All the web pages should have navigation aid so that it will be convenient for the user to move to the next page. The web pages should have graphics with less color.

Original Content
Each web page should be unique. By doing this, the user feels like navigating towards the next web page. Any overlap of the content may lose the interest of the user.

There are so many ways you can make the web site attractive. Website design services include the following:

  * Static web design
  * Dynamic web design
  * Website re-design
  
Static Website Design
A static website is the simplest way to showcase your business online. It is the easiest type of website to set up, but making changes to static websites require web programming knowledge.

Dynamic web design
If you require regular or constant updates to your website, consider dynamic website services.

Web site re-designs
As the Internet grows, outdated methodologies are causing more and more websites to fall to the side. It is important that you keep the look of your website fresh and maintain cutting-edge standards of design, navigation, and functionality. You should regularly schedule a complete redesign of your website, periodically giving your visitors a new and exciting experience. This service will ensure:

  * Professional execution of the website.
  * Increases your user’s usability.
  * Enhance the perception of your organization.
While designing a custom Website for our clients, we ensure the following:

  * Information architecture: structural design of shared information environments.
  * Accessibility

<a href=www.egbsystems.com/.../website_design.html> Flash website design</a>  is useful and helpful in creating innovative design of the website. This website also creates animation with sound effects, thereby leaving long-lasting impact on the users. Flash web pages are full of graphics and multimedia content.
You can do flash animations and corporate flash presentations so that the user will be attracted to the website. You can utilize flash in your website in forms of:-

  * Flash Introductory page
  * Animated Logo design
  * Photo galleries
  * Animation with background music
  * Flash Buttons
  * Flash Menus

<a href="http://www.egbsystems.com">http://www.egbsystems.com</a>
Wimpie Ratte
Wimpie Ratte on 10/30/2007 10:34 AM hi there. just wanted to say thanks ALOT for that post. i searched like a mad man trying to find something to export the ERD to SQL from visio and this worked smooth like a dream with zero hiccups.
ravi
ravi India on 2/23/2009 9:38 PM Really cool....
Nice, you save lot of time as well as money.It went smooth without any hurdles....
Ken White
Ken White United States on 3/5/2009 6:48 AM I appreciate your time and effort in finding this workaround. My company only provides me the tools they think I need. That never includes enterprise software versions or current development tools for that matter. Makes life interesting.
Mary
Mary United States on 5/4/2009 9:29 AM Awesome.  Thanks for this.  It was EXACTLY what I was looking for.
SEO
SEO United States on 6/18/2009 3:13 AM Good post.As the Internet grows, outdated methodologies are causing more and more websites to fall to the side. It is important that you keep the look of your website fresh and maintain cutting-edge standards of design, navigation, and functionality.
education software
education software United States on 6/23/2009 9:21 AM Thank you so much for this post. You'd think that I'd be easier to find this information on the internet, but I finally found what I've been looking for. Thank you again; you're saved me a bunch of time!

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading