What should i know about involving basic data types in SQL Server?
In my database i need
- Flags/bits, I assume I should use byte
- 64bit ids/ints
- 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 va开发者_开发知识库rchar(limit) unless i could use something ridiculously high like 128k. How do i specify 1byte - 8byte ints?
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
- 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
Here is the document.
http://msdn.microsoft.com/en-us/library/aa258271%28SQL.80%29.aspx
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
精彩评论