<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Design on Architecture and Data Blog</title>
    <link>https://sadalage.com/tags/design/</link>
    <description>Recent content in Design on Architecture and Data Blog</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 12 Jun 2017 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://sadalage.com/tags/design/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>ID generation with ORM&#39;s Table, Sequence or Identity strategy</title>
      <link>https://sadalage.com/post/id-generation/</link>
      <pubDate>Mon, 12 Jun 2017 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/id-generation/</guid>
      <description>&lt;p&gt;In this blog post, I will discuss ID generation techniques using the Object Relation Mapping frameworks such as Hibernate, Toplink, ActiveRecord, Entity Framework. When using hibernate or any other ORM mapping framework. There is a need to generate primary key values for the &amp;ldquo;id&amp;rdquo; columns. These values can be generated by using IDENTITY, SEQUENCE or TABLE strategies.&#xA;Generating custom values for primary keys or other values is a topic for another blog post.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Two factor authentication to authorize credit&#34;</title>
      <link>https://sadalage.com/post/two-factor-authentication-to-authorize-credit/</link>
      <pubDate>Wed, 13 Jul 2016 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/two-factor-authentication-to-authorize-credit/</guid>
      <description>&lt;p&gt;&#xA;  &lt;img src=&#34;https://sadalage.com/img/present-flow.jpg&#34; alt=&#34;Simple flow of credit file usage by Individual Citizens&#34;&gt;&#xA;&#xA;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Synonyms as abstraction layer</title>
      <link>https://sadalage.com/post/synonyms-as-abstraction-layer/</link>
      <pubDate>Fri, 15 Apr 2016 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/synonyms-as-abstraction-layer/</guid>
      <description>&lt;p&gt;In many development shops, developers are not allowed to access the database schema directly, and are not allowed to create tables, indexes, views etc, instead are given access via a different schema that allows &lt;em&gt;SELECT&lt;/em&gt;, &lt;em&gt;UPDATE&lt;/em&gt; and &lt;em&gt;DELETE&lt;/em&gt; access on data. The general reason is to avoid developers creating database objects without&lt;/p&gt;</description>
    </item>
    <item>
      <title>Transactions using Groovy.SQL with Spring annotations and connection pools</title>
      <link>https://sadalage.com/post/transactions_using_groovysql/</link>
      <pubDate>Mon, 14 Jan 2013 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/transactions_using_groovysql/</guid>
      <description>&lt;p&gt;When using Groovy with Spring framework,  interacting with the database can be done using the Groovy.SQL class which provides a easy to use interface. When using Groovy.SQL, if we have a need to do transactions, we have the &lt;strong&gt;.withTransaction&lt;/strong&gt; method that accepts a closure, to which we can pass in code to execute within the transaction.&#xA;In our project since we were using spring already, using annotations to define transactions would be a great. Standard &lt;strong&gt;@Transactional&lt;/strong&gt; annotations with Groovy.SQL will not work, since every place where the Groovy.SQL is used a new connection is acquired from the connection pool causing the database work to span multiple connections, which can result in dead-locks on the database. What we really want is that the database connection be the same across all invocations of Groovy.SQL with-in the same transaction started by the annotated method.&lt;/p&gt;</description>
    </item>
    <item>
      <title>MSSQL JDBC Driver behavior&#34;</title>
      <link>https://sadalage.com/post/mssql_jdbc_driver_behavior/</link>
      <pubDate>Sun, 22 Apr 2012 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/mssql_jdbc_driver_behavior/</guid>
      <description>&lt;p&gt;My latest project involves talking to MS-SQL Server using the JDBC driver and Java. While doing this we setup the database connection and had a simple SQL to get the &lt;em&gt;first_name&lt;/em&gt; and &lt;em&gt;last_name&lt;/em&gt; for a unique &lt;em&gt;user_id&lt;/em&gt; from the &lt;em&gt;application_user&lt;/em&gt; table in the database.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SELECT first_name,last_name&#xA;FROM application_user&#xA;WHERE user_id = ?&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Given the above SQL, we did not think too much about performance as the &lt;em&gt;user_id&lt;/em&gt; was indexed. The java code as below was used to run the SQL.&lt;/p&gt;</description>
    </item>
    <item>
      <title>With so much pain, why are stored procedures used so much</title>
      <link>https://sadalage.com/post/why_use_stored_procedures/</link>
      <pubDate>Wed, 19 Jan 2011 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/why_use_stored_procedures/</guid>
      <description>&lt;p&gt;I keep encountering situations where all the business logic for the applications is in stored procedures and the application layer is just calling the stored procedures to get the work done and return the data. There are many problems with this approach some of them are.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Writing stored procedure code is fraught with danger as there are no modern IDE&amp;rsquo;s that support refactoring, provide code smells like &amp;ldquo;variable not used&amp;rdquo;, &amp;ldquo;variable out of scope&amp;rdquo;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Schema less databases and its ramifications.</title>
      <link>https://sadalage.com/post/schema_less_databases/</link>
      <pubDate>Tue, 12 Oct 2010 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/schema_less_databases/</guid>
      <description>&lt;p&gt;In the No-SQL land schema-less is a power full feature that is advertised a lot, schema-less basically means you don&amp;rsquo;t have to worry about column names and table names in a traditional sense, if you want to change the column name you just start saving the data using the new column name Lets say you have a document database like mongoDB and you have JSON document as shown below.&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;{&#xA;&amp;#34;_id&amp;#34;:&amp;#34;4bc9157e201f254d204226bf&amp;#34;,&#xA;&amp;#34;FIRST_NAME&amp;#34;:&amp;#34;JOHN&amp;#34;,&#xA;&amp;#34;MIDDLE_NAME&amp;#34;:&amp;#34;D&amp;#34;,&#xA;&amp;#34;LAST_NAME&amp;#34;:&amp;#34;DOE&amp;#34;,&#xA;&amp;#34;CREATED&amp;#34;:&amp;#34;2010-10-12&amp;#34;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You have some corresponding code to read the documents from the database and lets say you lots of data in the database in the order of millions of documents. If you want to change the name of some attributes or columns at this point and the new JSON would look like&lt;/p&gt;</description>
    </item>
    <item>
      <title>Effective use of data for better customer experience.</title>
      <link>https://sadalage.com/post/effective_use_of_data/</link>
      <pubDate>Tue, 31 Aug 2010 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/effective_use_of_data/</guid>
      <description>&lt;p&gt;For more than seven years I have been getting offers for credit cards from Airlines and Banks. One particular bank has been sending me these solicitations for more than seven years. That is 12 mailings per year, more than 72 mailings so far, remember these are physical paper mailings not the electronic kind. I don&amp;rsquo;t like the junk, it hurts the environment and worst of all I think its not good use of the data they have. How hard is it to design a system around the data they have.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Schema design in a document database</title>
      <link>https://sadalage.com/post/schema_design_in_a_document_databases/</link>
      <pubDate>Wed, 28 Apr 2010 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/schema_design_in_a_document_databases/</guid>
      <description>&lt;p&gt;We are using MongoDB on our project, since mongo is document store, schema&#xA;design is somewhat different, when you are using traditional RDBMS data&#xA;stores, one thinks about tables and rows, while using a document database you&#xA;have to think about the schema in a some what different way. Lets say, we want&#xA;to save a customer object, when using a RDBMS we would come up with Customer,&#xA;Address, Phone, Email. They are related to each other as shown below.&#xA;&#xA;  &lt;img src=&#34;https://sadalage.com/img/customer.jpg&#34; alt=&#34;Relational Design&#34;&gt;&#xA;&#xA;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Ruby OCI 2.0 Array binding</title>
      <link>https://sadalage.com/post/ruby_oci_20_array_binding/</link>
      <pubDate>Thu, 08 Oct 2009 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/ruby_oci_20_array_binding/</guid>
      <description>&lt;p&gt;We have been doing some data moving lately using Ruby and &lt;a href=&#34;http://ruby-oci8.rubyforge.org&#34;&gt;Ruby-OCI&lt;/a&gt;. We started with Ruby OCI 1.0 and did use prepared statements with bind variables (since we are using oracle database and pulling data from an oracle database and pushing data to an oracle database). Later we found this really cool feature in Ruby-OCI8 2.0 where you can bind a whole array and just make one database trip for many database operations.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Create an Index for all FK Columns in the database</title>
      <link>https://sadalage.com/post/create_an_index_for_all_fk_columns/</link>
      <pubDate>Thu, 03 Sep 2009 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/create_an_index_for_all_fk_columns/</guid>
      <description>&lt;p&gt;Most of the time I have seen database foreign key constraints on tables without indexes on those columns. Lets say the application is trying to delete a row from the CUSTOMER table&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;DELETE FROM CUSTOMER WHERE CUSTOMERID = 1000;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When the database goes about deleting the customerId of 1000, if there are foreign key constraints defined on customerId, then the database is going to try to find if the customerId of 1000 is used in any of those tables. Lets say ORDER table has the customerId column, the database is going to issue&lt;/p&gt;</description>
    </item>
    <item>
      <title>Storing just the time in Oracle</title>
      <link>https://sadalage.com/post/storing_time_in_oracle/</link>
      <pubDate>Thu, 12 Feb 2009 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/storing_time_in_oracle/</guid>
      <description>&lt;p&gt;We came across a need to save just the Time in the database, the requirement is to store time of the day, like say the user likes to have Breakfast at 8.15AM and Lunch at 12.32PM etc. Off course oracle does not have a time only data type.  So we ended up using DATE as the data type and just setting the time. for example:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE FOO (PREFERRED_TIME DATE NULL);&#xA;INSERT INTO FOO (TO_DATE(&amp;#39;11:34&amp;#39;,&amp;#39;HH24:MI&amp;#39;));&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;oracle automatically sets the date to the first day of the current month. so when you do a select from the FOO table the data would be&lt;/p&gt;</description>
    </item>
    <item>
      <title>Considerations when using stored procedures for doing CRUD</title>
      <link>https://sadalage.com/post/considerations_when_using_procedures/</link>
      <pubDate>Tue, 03 Feb 2009 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/considerations_when_using_procedures/</guid>
      <description>&lt;p&gt;Some environments like to have access to the database tables routed via stored procedures.&#xA;Instead of using Create/Read/Update/Delete aka CRUD with DML, stored procedures are invoked with the parameters to perform the required operation. I&amp;rsquo;m not arguing about the benefits/pitfalls of this approach, if you have to do stored procedures, here are some things to look at.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Make the stored procedure handle one object/table only and not multiple objects or tables.&lt;/li&gt;&#xA;&lt;li&gt;Do not commit open transactions inside the stored procedures.&lt;/li&gt;&#xA;&lt;li&gt;Do not do business logic in stored procedures.&lt;/li&gt;&#xA;&lt;li&gt;If they are straight CRUD stored procedures, see if you can generate the stored procedure code using some metadata?&lt;/li&gt;&#xA;&lt;li&gt;Make sure creation and execution of the stored procedures is part of your &lt;a href=&#34;http://studios.thoughtworks.com/cruise-continuous-integration&#34;&gt;Continuous Integration&lt;/a&gt; build and developer build.&lt;/li&gt;&#xA;&lt;li&gt;Make sure stored procedures (or the metadata used to generate them) is under Version Control, have seen many problems when the stored procedure version does not match application code version&lt;/li&gt;&#xA;&lt;li&gt;Develop against the production stack database.&lt;/li&gt;&#xA;&lt;li&gt;Make sure exceptions thrown by the database are passed back to the application.&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Create a Index for every Foreign Key constraint created</title>
      <link>https://sadalage.com/post/create_a_index_for_every_foreign_key/</link>
      <pubDate>Tue, 15 Jul 2008 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/create_a_index_for_every_foreign_key/</guid>
      <description>&lt;p&gt;When creating a Foreign Key constraint on the database as shown below&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE BOOK ADD&#xA;    (CONSTRAINT FK_BOOK_AUTHOR FOREIGN KEY (AUTHORID)&#xA;     REFERENCES AUTHOR)&#xA;/&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the above example we are telling the database to check if the BOOK.AUTHORID is a valid value in the Author.AuthorID. When the Author table is being changed, the database does data verification on the BOOK table using SELECT against the BOOK table for the AUTHORID some thing like this&lt;/p&gt;</description>
    </item>
    <item>
      <title>Writing a SQL to generate a SQL</title>
      <link>https://sadalage.com/post/writing_a_sql_to_generate_a_sql/</link>
      <pubDate>Tue, 06 May 2008 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/writing_a_sql_to_generate_a_sql/</guid>
      <description>&lt;p&gt;We had a weird requirement on our project recently..&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Find all the Rows in All the tables that do not comply with the Constraints that we have in development but not in QA environments&lt;/p&gt;&lt;/blockquote&gt;</description>
    </item>
    <item>
      <title>Lessons from Re-Learning</title>
      <link>https://sadalage.com/post/relearning/</link>
      <pubDate>Thu, 27 Dec 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/relearning/</guid>
      <description>&lt;p&gt;I have been working on a project that I had worked in 2005, trying to get a handle on what I had done about 3 years back. Exploring code and the database has been fun, also discovering the data layout and building new set of data for production has been extremely entertaining. What I learnt from this whole experience was this &lt;em&gt;if your code(application or other wise) is not expecting data, this data should not be provided or even considered valid by the database, the database should be designed such that it does not even allow invalid combinations of the data.&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Why do Evolutionary Design</title>
      <link>https://sadalage.com/post/why_do_evolutionary_design/</link>
      <pubDate>Mon, 05 Nov 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/why_do_evolutionary_design/</guid>
      <description>&lt;p&gt;Why do Evolutionary Design or Iterative Design or Incremental Design?&#xA;Everyone who has not worked in an evolutionary manner asks this? My answer, if you think the system you designed is &lt;strong&gt;NOT GOING TO CHANGE EVER&lt;/strong&gt; then sure you can do design once and deploy once and you are done, move on to next project. But tell me one project you have been on, that does not have any changes in requirements, changes in technology, changes in look and feel etc after it was deployed.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Frameworks should not constrain your table design</title>
      <link>https://sadalage.com/post/frameworks_should_not_constrain_design/</link>
      <pubDate>Wed, 03 Oct 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/frameworks_should_not_constrain_design/</guid>
      <description>&lt;p&gt;Recently talking to someone about a persistence framework that they are using,&#xA;this framework creates a rows in the database table with just Primary Key value&#xA;and then later on updates the table row with values for other columns. Because&#xA;of this framework, the tables cannot have any NOT-NULL constraints defined.&lt;/p&gt;&#xA;&lt;p&gt;For example, the framework is doing&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-SQL&#34; data-lang=&#34;SQL&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;INSERT&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;INTO&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;customer&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;(customerId,&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;name,&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;birthdate)&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;VALUES&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;(&lt;span style=&#34;color:#3677a9&#34;&gt;1&lt;/span&gt;,&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;null&lt;/span&gt;,&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;null&lt;/span&gt;);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;UPDATE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;customer&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;set&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;name&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#39;FOO Name&amp;#39;&lt;/span&gt;,&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;birthdate&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#39;12/12/1978&amp;#39;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;WHERE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;customerId&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#3677a9&#34;&gt;1&lt;/span&gt;;&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You cannot have NON-NULL constraint defined on name or birthdate column, since&#xA;the INSERT statement would blow up, forcing you to change table design&lt;/p&gt;</description>
    </item>
    <item>
      <title>When does evolutionary design happen?</title>
      <link>https://sadalage.com/post/when_does_evolutionary_design/</link>
      <pubDate>Tue, 28 Aug 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/when_does_evolutionary_design/</guid>
      <description>&lt;p&gt;A question I get, mostly related to the evolutionary database design and development. When the pair (team) gets a new feature (story) to work on, the team looks at the existing table/database design and sees if the current design is enough to implement the feature they are working on. If the currency database design does support the feature they are trying to implement, then they do not have to change the database at all, they will move on to implement the feature and change the application code as necessary.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Enforcing your assumptions about database functionality</title>
      <link>https://sadalage.com/post/enforcing_your_assumptions/</link>
      <pubDate>Fri, 08 Jun 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/enforcing_your_assumptions/</guid>
      <description>&lt;p&gt;When you are writing xUnit tests you are in certain ways trying to make sure that the test breaks when the code that is being tested changes the assumptions you made when writing the Test and Production code.&lt;/p&gt;&#xA;&lt;p&gt;Similarly if you are relying on the database to throw a error when you put invalid data, then you should write a test around this assumption, so that when someone changes the database to not behave the way you assumed it to behave, the test you wrote will break and it will force the team to think about the change to the database that is being undertaken. If the change is really required, then the team would fix the test else rollback the change being made.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Nulls need special love</title>
      <link>https://sadalage.com/post/nulls_need_special_love/</link>
      <pubDate>Thu, 15 Feb 2007 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/nulls_need_special_love/</guid>
      <description>&lt;p&gt;The following SELECT statement in code&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;stmt&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;DB.&lt;span style=&#34;color:#bbb&#34;&gt;prepare&lt;/span&gt;(&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#34;select id,name,state,zip &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;+&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#34;from customer &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;+&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#34;where &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;+&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#34;phone = ? &amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;+&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;        &lt;/span&gt;&lt;span style=&#34;color:#ed9d13&#34;&gt;&amp;#34;and active = ?&amp;#34;&lt;/span&gt;);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;stmt.&lt;span style=&#34;color:#bbb&#34;&gt;setString&lt;/span&gt;(1,&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;customerPhone);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;stmt.&lt;span style=&#34;color:#bbb&#34;&gt;setBoolean&lt;/span&gt;(2,&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;isActive);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;stmt.&lt;span style=&#34;color:#bbb&#34;&gt;execute&lt;/span&gt;();&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;where &lt;strong&gt;customerPhone&lt;/strong&gt; and &lt;strong&gt;isActive&lt;/strong&gt; are values you would pass in to the SELECT before its executed. Everything is fine when one day the value passed for &lt;strong&gt;customerPhone&lt;/strong&gt; is NULL. For a database (Oracle is what I know most) a NULL will never be equal to NULL , the SELECT will not return rows where the customer.phone is NULL, leading to wrong results. The SELECT will have to be changed to&lt;/p&gt;</description>
    </item>
    <item>
      <title>Implementing Make Column Non Nullable</title>
      <link>https://sadalage.com/post/implementing_make_column_non_nullable/</link>
      <pubDate>Fri, 15 Dec 2006 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/implementing_make_column_non_nullable/</guid>
      <description>&lt;p&gt;While working on a Legacy Application with Legacy Database design as part of fixing a bug, I thought this bug would not have ever happened if a particular column was defined as &lt;strong&gt;Non Nullable&lt;/strong&gt; since this particular column was the identifier to the parent table.&lt;/p&gt;&#xA;&lt;p&gt;We had a Customer table and the all the names a customer could have like LegalName, LongName, ShortName etc are stored in the CustomerName table. CustomerName cannot exist without Customer hence its logical that the CustomerName.CustomerID column cannot be nullable and should also have a Foreign Key constraint enforcing the relationship. Implementing just the Foreign Key constraint is not enough since the application could potentially be inserting null values in the CustomerName.CustomerID creating orphan records.&lt;/p&gt;</description>
    </item>
    <item>
      <title>To allow NULLs or NOT</title>
      <link>https://sadalage.com/post/to_null_or_not/</link>
      <pubDate>Wed, 08 Feb 2006 00:00:00 +0000</pubDate>
      <guid>https://sadalage.com/post/to_null_or_not/</guid>
      <description>&lt;p&gt;Database designs I have seen tend to &lt;em&gt;not constrain&lt;/em&gt; the data in the database. For example make the &lt;em&gt;Item.ManufacturerID&lt;/em&gt; non-nullable and make it a foreign key to the &lt;em&gt;Manufacturer&lt;/em&gt; table. Similarly &lt;em&gt;Manufacturer.Name&lt;/em&gt; and &lt;em&gt;Item.Rate&lt;/em&gt; as non-nullable columns. In any greenfield application (existing production application is a topic for another post). When you design table(s) lets say you have &lt;em&gt;Item&lt;/em&gt; and &lt;em&gt;Manufacturer&lt;/em&gt; table as shown below&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#d0d0d0;background-color:#202020;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;CREATE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;TABLE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;Item&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;(ItemID&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#24909d&#34;&gt;NUMBER&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;NOT&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;NULL&lt;/span&gt;,&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;ManufacturerID&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#24909d&#34;&gt;NUMBER&lt;/span&gt;,&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;Name&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;VARCHAR2(&lt;span style=&#34;color:#3677a9&#34;&gt;128&lt;/span&gt;),&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;Rate&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#24909d&#34;&gt;NUMBER&lt;/span&gt;,&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;CONSTRAINT&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;PK_ITEM&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;              &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;PRIMARY&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;KEY&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;(ItemID)&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;CREATE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;TABLE&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;Manufacturer&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;(ManufacturerID&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#24909d&#34;&gt;NUMBER&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;NOT&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;NULL&lt;/span&gt;,&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;Name&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;VARCAHR2(&lt;span style=&#34;color:#3677a9&#34;&gt;128&lt;/span&gt;),&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;CONSTRAINT&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;PK_MANUFACTURER&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;              &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;PRIMARY&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#6ab825;font-weight:bold&#34;&gt;KEY&lt;/span&gt;&lt;span style=&#34;color:#666&#34;&gt; &lt;/span&gt;(ManufacturerID)&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#666&#34;&gt;&lt;/span&gt;);&lt;span style=&#34;color:#666&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For now let&amp;rsquo;s talk about &lt;strong&gt;NOT NULL&lt;/strong&gt; constraint. Many say they don&amp;rsquo;t make columns non-nullable, because they don&amp;rsquo;t know the requirements at design time, or they don&amp;rsquo;t want their tests to create elaborate sets of data, or that the application enforces the constraint then why enforce the constraint on the database?&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
