Welcome to PlantUML Q&A, where you can ask questions and receive answers from other members of the community.

You can also submit new features request and vote for them.

Database modeling

+4 votes
Hi, I wonder how I can use this great tool to draw database modelling. The closest feature I can think of at the moment is object diagram. However it does not support 'index', 'unique', 'primary key', 'compound primary key' and the like. Thanks
asked Feb 22, 2013 in Wanted features by anonymous

2 Answers

+3 votes

Some users are using class diagram, and preprocessing facilities. http://plantuml.sourceforge.net/preprocessing.html
You can define then something like :

@startuml
!define table(x) class x << (T,#FFAAAA) >>
!define primary_key(x) <u>x</u>
hide methods
hide stereotypes

table(FOO1) {
  primary_key(FIELD1)
  FIELD2
}
@enduml

answered Feb 22, 2013 by plantuml (113,980 points)
Hi, thank you very much. I really appreciate this answer. One thing remains, how can I link attributes across class? Currently I have to do in package and class level.


@startuml

package user {
  class user.id <pk>
  class email <unique>
  class name <index>
}

package class {
  class id
  class uid "1" - "n" user.id
}

package cpk {
  cid - pid: cpk
}

@enduml
Unfortunatly, this is something you cannot do with PlantUML today.
This is theorically possible (because GraphViz allows this, see http://www.graphviz.org/doc/info/html1.gif on http://www.graphviz.org/doc/info/shapes.html).
So, in future version, maybe PlantUML will allow to link attributes, but not on the short term.
Regards,
With last beta https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

You can now have:

@startuml
class Foo {
+ field1
+ field2
}

class Bar {
+ field3
+ field4
}

Foo::field1 --> Bar::field3 : foo
Foo::field2 --> Bar::field4 : bar
@enduml

Note that this is still a beta version, so it may not work/crash in some case.
Feedback welcome!
0 votes

I was need similar feature for RDBMS and used class diagrams. IMO with simple conventions (like usage of protected and public fields of class diagram for PKs and indexes) it good enough for visualizing.

@startuml

class dummy {
  Sample table.
  ==
  #id int(10) -- A comment
  field1 int(10)
  .. Comment line, ignored ..
  field2 varchar(128)
}

@enduml


Additionally for generating SQL DDL from PlantUML diagram sources I created simple Python script (for MySQL in my case) https://github.com/grafov/plantuml2mysql. It helpes me maintain real database with single source in format of class diagram. I think it may be easily adapted for other RDBMS as well.

answered Jun 27, 2016 by axel (160 points)
We are thinking about allowing this kind of diagrams (this is not working yet)

@startuml
class Foo {
+ field1
+ field2
}

class Bar {
+ field3
+ field4
}

Foo::field1 --> Bar::field2 : link between fields
@enduml

However, this needs some works...

About primary key, you can use the sprite feature (see http://plantuml.com/sprite.html )

So that you can have something like:

http://www.plantuml.com/plantuml/uml/JOxVQuCm7CJVyrTy7_RGmdI9zjTW7NILEboTPIiJ6QD4pLmWIJNQJXtxtnSOGb_kkFlSmzMbvWs3AsEIwWxUoRmbpWsPzH-GHjNPPGIxU1syz3jrksaFpt4oLnDM1Uu-g6VH6vsM-zApfermasxpw5iJhwvMaOeB-XsNMECddnRUoG-JC6ZJK3-q_NON72BiOumGoWIjQyXFKdRmWm1UgIm5WuQcWjacBvT6xePtzy1LCo9uR4gU3m4i2rQG7QLagZ7aapEHaukfRSFwduBWYbq3BzHHizo0OUx0cUhiY-eHSHPZzFi7
I've seen you introduced that feature in V8045, unfortunately i'm using the idea plugin which is still on V8043.
Can i upgrade myself or do you have an estimate when a new version will be available?
You may try to upgrade yourself. Change plantuml.jar should to the trick (although I do not know how to do it on the idea plugin).
Support This Project Offer 250 Mo! Follow PlantUML on Twitter
...