Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

TinyInt or Char(1)?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ronald S. Cook - 30 Nov 2006 17:58 GMT
In a database table we will have a column "Round" for which round of feeding
the record applies to at a cattle ranch.  The  value will always be either
1, 2, or 3 since we feed just that many times per day (kind of like
breakfast, lunch, and dinner).

In the table, would you make the column "Round" a TinyInt data type, or a
char(1)?  I've heard that you shouldn't use Int unless there might ever be
some sort of math involved, but I'm not sure.  I'm just loooking for the
"best practice" if there is one to apply to all such situations.

Thanks,
Ron Cook
Michael D. Ober - 30 Nov 2006 18:16 GMT
I would use int and then create an enum representing each valid value.
Reference the enum in your code.

Mike Ober.

> In a database table we will have a column "Round" for which round of
> feeding the record applies to at a cattle ranch.  The  value will always
[quoted text clipped - 8 lines]
> Thanks,
> Ron Cook
Rad [Visual C# MVP] - 30 Nov 2006 18:36 GMT
I'd use Int myself, then I can use that as an enum

>In a database table we will have a column "Round" for which round of feeding
>the record applies to at a cattle ranch.  The  value will always be either
[quoted text clipped - 8 lines]
>Thanks,
>Ron Cook

--

Bits.Bytes.
http://bytes.thinkersroom.com
Jon Skeet [C# MVP] - 30 Nov 2006 19:13 GMT
> I'd use Int myself, then I can use that as an enum

Why not use TinyInt and then use an enum which has byte as its
underlying type?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Rad [Visual C# MVP] - 30 Nov 2006 20:03 GMT
TinyInt I meant. But then again int are just as workable I would think

>> I'd use Int myself, then I can use that as an enum
>
>Why not use TinyInt and then use an enum which has byte as its
>underlying type?
--

Bits.Bytes.
http://bytes.thinkersroom.com
Michael D. Ober - 30 Nov 2006 21:36 GMT
Can you give an example of using a byte as the underlying type of the enum?
I just need the syntax as I wasn't aware this could be done.

Thanks
Mike Ober.

>> I'd use Int myself, then I can use that as an enum
>
> Why not use TinyInt and then use an enum which has byte as its
> underlying type?
Jon Skeet [C# MVP] - 30 Nov 2006 21:51 GMT
> Can you give an example of using a byte as the underlying type of the enum?
> I just need the syntax as I wasn't aware this could be done.

public enum MyEnum : byte
{
   FirstValue,
   SecondValue
}

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Michael D. Ober - 30 Nov 2006 22:07 GMT
Thanks.

Mike.
>> Can you give an example of using a byte as the underlying type of the
>> enum?
[quoted text clipped - 5 lines]
>    SecondValue
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.