blancer.com
Visual Database Creation with MySQL Workbench In this tutorial, we’ll focus on the Data Modeling
aspect to create a database from scratch, and then
In today’s tutorial, you’ll learn how to use a visual have just a quick look at the SQL editor to execute
database modeling utility to draw a database dia- our generated SQL script and create the database
gram and automatically generate SQL. Specifically, within MySQL.
we’ll review how to use MySQL Workbench, a cross-
platform, visual database design tool. MySQL Workbench is available for Windows, Linux
and Mac OSX. There are two different editions: the
What is MySQL Workbench? Community OSS Edition and the commercial Stan-
dard Edition. The community edition is Open Source
MySQL Workbench is a powerful tool developed by and GPL licensed, as you’d expect. It’s fully functio-
MySQL with three primary areas of functionality: nal, and is the one we’ll be using in this article. The
commercial edition adds some extra functionalities,
• SQL Development: Replaces MySQL query such as schema and model validation or documen-
browser. Allows the user to connect to an tation generation.
existing database and edit and execute SQL
queries. Note: this tutorial is based on the Community OSS
• Data Modeling: Complete visual database Edition version 5.2 (5.2.16), currently in beta release
design and modeling. at the time of the writing (April 2010).
• Database Administration: Replaces
MySQL administrator. Graphic interface to Planning our Database
start/stop servers, create user accounts, edit
configuration files, etc. To learn how to use MySQL Workbench, we’ll use
Click here to send your feedback
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 1
11/11/2010 14:11
blancer.com
It’s time to launch Workbench. In the data modeling We can have several schemas for the same data-
part of the home screen, we click Create new EER base model in the same way we can have several
Model’, and the following screen appears: databases in a MySQL server. Each schema will be
Printed with
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 2
11/11/2010 14:11
blancer.com
a schema with five tables defined, and then create • PK – Primary key
a new diagram to define two more tables using the • NN – Not null
visual editor. The diagram will contain only two • UQ – Unique
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 3
11/11/2010 14:11
blancer.com
• BIN – Binary
• UN – Unsigned
• ZF – Zero fill
• AI – Autoincrement
Go Visual
Now you just have to double click the table, and the
editor tab appears to edit the name, columns, types,
etc.- the same way as we did before.
““ A relationship is considered identifying
when one table is entirely dependent on the
other to exist.
joliprint
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 4
11/11/2010 14:11
blancer.com
Also, in the case of 1:1 and 1:n identifying rela- The “sixth symbol” creates a rela-
tionships, the foreign key introduced will be part of tionship using existing columns,
the primary key for that table, forming a composite meaning that you have already included the ne-
Click here to send your feedback
primary key. cessary foreign keys in your tables and created the
necessary join tables (n:m mapping tables). Since
The good news is that MySQL Workbench knows we’ve already created these Join tables, we don’t
these rules better than most of us. We just draw need n:m relationships; only 1:n is available.
our lines, and the foreign keys or join tables will
be automatically be created. We can also choose to When we have all our relationships defined, our
do it manually, as we’ll see shortly. diagram should looks like so:
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 5
11/11/2010 14:11
blancer.com
Generating SQL
joliprint
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 6
11/11/2010 14:11
blancer.com
Conclusion
MySQL Workbench is an impressive tool. We have
only seen a few basic possibilities in the data mo-
deling part, and only peeked at the SQL editor in
Click here to send your feedback
If you don’t want to set the password here, you’ll be the second half of this tutorial. We learned how
prompted for it when needed. Click “Test Connec- to create a database visually and draw diagrams
tion” to check if your parameters are correct, and that can be kept as documentation. You can export
then click close. the diagrams as a PNG, SVg, PDF or PostScript file.
Thanks for reading, and let me know what you think!
Now, to load the script, we’ll use the SQL editor. In
the main menu select Database/Query Database; a
window prompts you to select a connection, and
then the SQL editor tab opens.
joliprint
Printed with
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 7
11/11/2010 14:11
blancer.com
More Related
Click here to send your feedback
joliprint
Printed with
http://blancer.com/tutorials/25445/visual-database-creation-with-mysql-workbench/
Page 8