Unix Technical Forum

the datatype

This is a discussion on the datatype within the SQL Server forums, part of the Microsoft SQL Server category; --> hello ! I got some problems here. I have an attribute that determines the unit of something,e.g. the size ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:24 PM
John Kevien
 
Posts: n/a
Default the datatype


hello !

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!



*** Sent via Developersdex http://www.developersdex.com ***
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:24 PM
--CELKO--
 
Posts: n/a
Default Re: the datatype

>> 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:24 PM
Tony Rogerson
 
Posts: n/a
Default Re: the datatype

If you are just storing the description, eg...

mm
seconds
n-page

then I'd hold them using nvarchar and size it according to the maxium length
you expect, if its just the above then nvarchar(7).

If you are talking about the units themselves then i'd go down this
route....

create table unit_type (
id int not null identity constraint sk_unit_type unique clustered,
name nvarchar(7) not null constraint pk_unit_type primary key
nonclustered
)

create table measurement (
unit_type_id int not null references unit_type( id ),
unit decimal( 10, 5 ) not null
)

Hope that helps.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials


"John Kevien" <kevien-2002@163.com> wrote in message
news:mJBag.1$RV2.122@news.uswest.net...
>
> hello !
>
> 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!
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 07:24 PM
Neil
 
Posts: n/a
Default Re: the datatype

Just curious: why nvarchar instead of varchar?

"Tony Rogerson" <tonyrogerson@sqlserverfaq.com> wrote in message
news:e4fa0l$327$1$8300dec7@news.demon.co.uk...
> If you are just storing the description, eg...
>
> mm
> seconds
> n-page
>
> then I'd hold them using nvarchar and size it according to the maxium
> length you expect, if its just the above then nvarchar(7).
>
> If you are talking about the units themselves then i'd go down this
> route....
>
> create table unit_type (
> id int not null identity constraint sk_unit_type unique
> clustered,
> name nvarchar(7) not null constraint pk_unit_type primary key
> nonclustered
> )
>
> create table measurement (
> unit_type_id int not null references unit_type( id ),
> unit decimal( 10, 5 ) not null
> )
>
> Hope that helps.
>
> Tony.
>
> --
> Tony Rogerson
> SQL Server MVP
> http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a
> SQL Server Consultant
> http://sqlserverfaq.com - free video tutorials
>
>
> "John Kevien" <kevien-2002@163.com> wrote in message
> news:mJBag.1$RV2.122@news.uswest.net...
>>
>> hello !
>>
>> 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!
>>
>>
>>
>> *** Sent via Developersdex http://www.developersdex.com ***

>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 07:24 PM
Tony Rogerson
 
Posts: n/a
Default Re: the datatype

Hi Neil,

Its the Microsoft recommendation for string data types, use the N (unicode)
versions, there are a few things that require unicode if you use SSIS too.

I'm finding it a hard habbit to get into!

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials


"Neil" <nospam@nospam.net> wrote in message
news:wpIag.3219$x4.3114@newsread3.news.pas.earthli nk.net...
> Just curious: why nvarchar instead of varchar?
>
> "Tony Rogerson" <tonyrogerson@sqlserverfaq.com> wrote in message
> news:e4fa0l$327$1$8300dec7@news.demon.co.uk...
>> If you are just storing the description, eg...
>>
>> mm
>> seconds
>> n-page
>>
>> then I'd hold them using nvarchar and size it according to the maxium
>> length you expect, if its just the above then nvarchar(7).
>>
>> If you are talking about the units themselves then i'd go down this
>> route....
>>
>> create table unit_type (
>> id int not null identity constraint sk_unit_type unique
>> clustered,
>> name nvarchar(7) not null constraint pk_unit_type primary key
>> nonclustered
>> )
>>
>> create table measurement (
>> unit_type_id int not null references unit_type( id ),
>> unit decimal( 10, 5 ) not null
>> )
>>
>> Hope that helps.
>>
>> Tony.
>>
>> --
>> Tony Rogerson
>> SQL Server MVP
>> http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a
>> SQL Server Consultant
>> http://sqlserverfaq.com - free video tutorials
>>
>>
>> "John Kevien" <kevien-2002@163.com> wrote in message
>> news:mJBag.1$RV2.122@news.uswest.net...
>>>
>>> hello !
>>>
>>> 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!
>>>
>>>
>>>
>>> *** Sent via Developersdex http://www.developersdex.com ***

>>
>>

>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:20 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com