Quiz 2 - SQL Server - Datatypes Flashcards
exact numerics
- When data store is known precisely and no approximation is needed/allowed
- For example all integer values. Even values with decimals such as 10.23 or 1.23456
- These data types are useful for all integer values as well as values with decimals where exactness is useful.
- For example: data tracking money – the number of decimal places need tracking is small, but require exactness.
approximate numerics
- The numbers stored are made up of two parts: the mantissa and the exponent.
- The algorithm used to produce these two parts from a number is not precise.
- As a result, what is inserted would not be exactly what is stored and retrieved.
- These data types are useful for scientific, statistical and engineering purposes.
- These applications require much higher level of precision (number of digits stored) but are fine with the minor approximations in the storage.
date and time
For storing both data as well as time
character strings
- Series of character data made up of letters, digits and symbols.
- Each character is stored using 1-byte of space (ANSI character set which is 256 characters).
- Maximum length allowed is 8000 characters (8000 bytes), because more than that cannot be stored in single page.
unicode character strings
• Similar to character strings, but using a broader character set (Unicode Character Set).
• Each character is stored using 2-byte of space.
• Note: Unicode character set can potentially represent a maximum of 65,536 characters.
Maximum length allowed is 4000 characters (8000 bytes).
binary strings
• for storing binary data (1s and 0s)
SQL: BIGINT
- storage: 8 bytes
* values allowed: -2^63 to 2^63-1 (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)
SQL: INT
- storage: 4 bytes
* values allowed: -2^31 to 2^31-1 (-2,147,483,648 to 2,147,483,647)
SQL: SMALLINT
- storage: 2 bytes
* values allowed: -2^15 to 2^15-1 (-32,768 to 32,767)
SQL: TINYINT
- storage 1 byte
- values allowed: 0 to 2^8-1 (0 to 255)
- note: does not allow storing negative values
SQL: DECIMAL(p,s)
- fixed precision and scale numeric datatype
- When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1.
- p (precision) is the maximum total number of decimal digits that can be stored, including both to the left and to the right of the decimal point
- precision must be a value from 1-38
- default precision is 18
- s (scale) is the maximum number of decimal digits that can be stored to the right of the decimal point
- Scale must be a value from 0-p.
- Scale can be specified only if precision is specified.
- default scale is 0; therefore, 0 <= p.
SQL: NUMERIC
same as DECIMAL
SQL: MONEY
- storage: 8 bytes
- values allowed: -922,337,203,685,477.5808 to 922,337,203,685,477.5807
- note: stored values are accurate to a ten-thousandth of the monetary unit
SQL: SMALLMONEY
- storage: 4 bytes
- values allowed: - 214,748.3648 to 214,748.3647
- note: stored values are accurate to a ten-thousandth of the monetary unit
SQL: BIT
• integer data type that can take a value of 1, 0, or NULL