Lean Code – Visual Tools

I’ve said it many times and it bears repeating:

Be careful who teaches you!

The following paragraph is cited from a book titled “Getting started with IntelliJ IDEA” by Hudson Orsine Assumpcao (October 2013), Chapter 3 “Working with Databases”.

Looking at the visual tools, I didn’t find a way to add auto_increment in a column, so, we will do it using the query console …

The Problem

I was somewhat surprised to read the statement cited above since the SQL Preview pictured in the book suggests that the code could be modified or edited to include an auto_increment attribute to the id column before executing it.

Microsoft SQL Server uses the IDENTITY attribute to “auto_increment” on a column and you will quickly discover that it is not possible to add an IDENTITY attribute to a column after the table is created.

Surprisingly, immediately after creating the first table using the “graphical interface”, two additional tables without an auto_increment are created using the console where the SQL is entered directly from the keyboard.

Although this section of the book is premised on using MySQL, it is by no means an attempt to teach SQL.  If you are using Microsoft’s SQL Server, you will find yourself recreating the tables correctly as suggested by this minimalist code snippet:

CREATE TABLE PhoneNumbers (
  id int IDENTITY(1,1) NOT NULL,
  PhoneNumber varchar(13) NOT NULL,

  PRIMARY KEY (id)
);

While I can appreciate that relational database providers offer and exhibit differing features and behaviors, choosing to alter a column other than one requiring an auto_increment would have been a better choice to demonstrate IntelliJ’s database features, especially as a segue to using the console.

The greater lesson here is the author’s purposeful demonstration that visual tools do not always provide or support the functionality that our application demands.  The author duly notes other “visual tool” short falls in latter chapters in the book as well.

IntelliJ IDEA is a very powerful IDE and it can be very easy to assume that certain automation such as code completion will provide the code we need.  If you’re new to Java or other language of your choice, be careful to watch and learn from the visual tools you are using and know that the solution may not always be what your application requires.

Until Next Time, STAY lean!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.