SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Wednesday, May 17, 2006

the datatype

SQL Apprentice Question
I got some problems here. I have an attribute that determines the unit
of something,e.g. the size of using "mm" , the length of using "seconds"
and something others may using "n-page", so ,which data type should I
use. the "nvarchar" or others?


thank you very much!

Celko Answers
>> I have an attribute that determines the unit of something,e.g. the size of using "mm" , the length of using "seconds" and something others may using "n-page", so ,which data type should I use. the "nvarchar" or others? <<


You need to learn how a relational design works. What meaningful name
could you give such a column? "some_kind_of_unit" or "don't_know_unit"
or "could_be_anything" is a bit vague. Since seconds cannot be
transformed into volts, etc. this column is in violation of !NF -- it
holds several totally different things, like field in a file system.

Units of measure are part of an attribute's value, not an attribute.
You are confusing data and meta-data. Get of a copy of
SQL PROGRAMMING STYLE or SQL FOR SMARTIES and read the chapters on scales and
measurements, and the design of encoding schemes.

No comments: