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)
Facundo says
Do you have any .xslt for Oracle?
Thanks
Donn Felker says
I do not have a xslt for Oracle. Sorry!
Busi says
Is there an ability to generate SQL code for check constraints and indexes using the Orthogonal toolbox?
haha says
replica designer bags I recommend the package
replica designer handbags Of inexpensive package
air max 2012 Comfortable shoes
nike shox turbo Cheap shoes
men puma shoes Unique design Shoes
air max 90 Variety of shoe styles
wholesale puma shoes Pretty shoes
puma shoes sale Cheap comfortable shoes
timberland mens boots Discount a lot of
gucci women shoes Quite well shoes
louis vuitton outlet Very nice
haha says
authentic nfl jerseys Inexpensive items
coach bags on sale I am confident with his
coach outlet store online First step in success
coach outlet online Workmanship
coach bags outlet Value of goods
coach outlet store Of love
wholesale designer bags Beautiful lines
coach bags outlet There range of children
cheap coach What are you waiting
wholesale nfl jerseys Is always expected
authentic nfl jerseys It is pretty good
haha says
authentic nfl jerseys Inexpensive items
coach bags on sale I am confident with his
coach outlet store online First step in success
coach outlet online Workmanship
coach bags outlet Value of goods
coach outlet store Of love
wholesale designer bags Beautiful lines
coach bags outlet There range of children
cheap coach What are you waiting
wholesale nfl jerseys Is always expected
authentic nfl jerseys It is pretty good
Coach Factory Outlet says
http://buycoachfactoryoutletsz.com