user34537
user34537

Reputation:

Basic Datatypes in SQL Server?

What should i know about involving basic data types in SQL Server?

In my database i need

  1. Flags/bits, I assume I should use byte
  2. 64bit ids/ints
  3. a variable length string. It could be 5 letters it could be 10,000 (for desc but i plan to allow unlimited length usernames)

Is there a TEXT type in SQL Server? I dont want to use varchar(limit) unless i could use something ridiculously high like 128k. How do i specify 1byte - 8byte ints?

Upvotes: 1

Views: 1490

Answers (4)

Randy Minder
Randy Minder

Reputation: 48522

Others have already provided good answers to your question. If you are doing any .NET development, and need to map SQL data types to CLR data types, the following link will be quite useful.

http://msdn.microsoft.com/en-us/library/bb386947.aspx

Randy

Upvotes: 1

marc_s
marc_s

Reputation: 755361

For 1), use BIT - it's one bit, e.g. eight of those fields will be stuck into a single byte.

For 2), use BIGINT - 64-bit signed int

For 3), definitely do NOT use TEXT/NTEXT - those are deprecated as of SQL Server 2005 and up.

Use VARCHAR(MAX) or NVARCHAR(MAX) for up to 2 GB of textual information instead.

Here's the list of the SQL Server 2008 data types:

http://msdn.microsoft.com/en-us/library/ms187594.aspx

Upvotes: 4

gbn
gbn

Reputation: 432657

  • Flags/bits, I assume I should use byte

Use "bit" which is exactly that: one bit

  • 64bit ids/ints

bigint is 64 bit signed

  • a variable length string. It could be 5 letters it could be 10,000 (for desc but i plan to allow unlimited length usernames)

varchar(max) is up to 2GB. Otherwise varchar(8000) is the conventional limit

Microsoft even put into a nice handy web page for you

Upvotes: 3

Related Questions