It has been some time since I took my intro to Relational Databases back in the spring of
07. So today I decided to do some research on MySQL and the database in general. So without further adieu, here are some helpful notes.
- char vs varchar – If a string is inserted of 20 character in length is inserted into a char(30) field, it will take up 30 characters in the database. If that same string 20 characters in length is inserted into a varchar(30) field, it will take up just 20 characters of space.
- Int vs smallint – Smallint is used if your number will not exceed the range of -32768 – 32768. Int is used when the number falls between -2147483648 – 2147483648. It is also worthy to mention the other types of integers, tinyint, mediumint, and bigint
Database normalization is quite possibly one of the blurriest areas for me. Going from teachers that profess a web site needs to be normalized to other teachers that say ‘if it works don’t fix it’ I have had to find a middle ground for now until I can make a decision and learn more about it. For most projects I do, I follow through to third normal form (3NF). This prevents from having redundancy, duplicate data, as well as prevents data anomalies from occurring. Data anomalies are incorrect/inconsistent data that is the result of updates or insertions that create “duplicate” records.
On another note, I just purchased a new MySQL book MySQL Crash Course by Ben Forta. It looks to be an excellent replacement for my current book. Just looking through the table of contents and reading a few pages, it covers way more than my previous book I purchased for my relational database class. So stay tuned for MySQL Notes ver.2.