Sunday, March 16, 2014

Data Types or Attributes

If you are in data warehousing there will come a time to to data projections on tables. The basic to see on SQL Server you can use the following query:

SELECT * FROM sys.types

from there you will get a list of the data types:

image, text, uniqueidentifier, date, time, datetime2, datetimeoffset, tinyint, smallint, int, smalldatetime, real, money, datetime, float, sql_variant, ntext, bit, decimal, numeric, smallmoney, bigint, hierarchyid, geometry, geography, varbinary, varchar, binary, char, timestamp, nvarchar, nchar,
xml, sysname

Character data types













Here are a few general rules that should help:

  • Don't use nchar or nvarchar unless you truly need it. (Unicode provides a unique number for up to 65,536 characters. ANSI, the one most of us are most familiar with, has only 256.) Unless you're working with an international application, you probably don't need a Unicode data type.
  • Use the smallest data type necessary, but make sure it can accommodate the largest possible value.
  • Use a fixed-length data type when the values are mostly about the same size.
  • Use a variable length when the values vary a lot in size.
 Integer data types










Assigning the appropriate integer data type isn't as confusing as choosing a character data type. Simply use the smallest integer data type that accommodates the largest possible value.

Precision storage requirements





 





Float and real data type restrictions








The real data type is the same as float(24) -- a floating data type with 24 digits to the right of the decimal point

Smalldatetime and datetime restrictions



 









Smallmoney and money restrictions



No comments:

Post a Comment