Data Types Flashcards
Name 6 high level categories of data types.
- Exact Numeric (INT, NUMERIC)
- Approximate numeric (FLOAT, REAL)
- Character strings (CHAR, VARCHAR)
- Unicode character strings (NCHAR, NVARCHAR)
- Binary Strings (BINARY, VARBINARY)
- Date and Time (DATE, TIME, DATETIME2, SMALLDATETIME,DATETIME,DATETIMEOFFSET)
There are more than this, but these are the 6 mentioned in the book.
SQL Server 70-461 02-02a
What is important to consider when choosing a data type?
- Data types are constraints. Use the appropriate data type to invoke appropriate data constraints.
- The operators and functions you will be able to use.
- The size of the data type.
- Whether the data type should be fixed or variable.
- Whether to use a Regular or Unicode character type.
- Length of the data type.
SQL Server 70-461 02-02a
Where should formatting of a value take place?
Formatting of a value should be the responsibility of the application when data is presented.
For example, you shouldn’t use a data type of string because you want a date to be displayed in a specific format. You should use a date data type and then depend on the application to display it in the appropriate format.
SQL Server 70-461 02-02a
When should you use the FLOAT or REAL data types?
When you are certain that imprecise numbers will be acceptable.
REAL or FLOAT data types are approximate; therefore, not all values in the data type range can be represented exactly. If you need your value in the data type to be exact, then do not use one of these data types.
SQL Server 70-461 02-02a
Why use FLOAT or REAL data types when there are more precise data types available to use?
The benefit in these types is that they can represent very large and very small numbers beyond what any other numeric type that SQL Server supports can represent.
So, for example, if you need torepresent very large or very small numbers for scientific purposes and don’t need completeaccuracy, you may find these types useful.
SQL Server 70-461 02-02a
How is a data type a constraint?
The data type you choose will limit the type of data that can be entered.
For example, if you choose a date data type then no value other than a valid date will be allowed, if you choose a numeric data type then only numbers will be allowed, etc.
SQL Server 70-461 02-02a
Why should you consider what operators and functions you will be able to use when selecting a data type?
Choosing the right data type ensures you will be able to use the operators and functions best suited to the values entered.
For example, if you use a numeric data type then + would add values. If you use a character data type then + will concatenate values.
SQL Server 70-461 02-02a
What is a general rule when choosing the size of the data type?
Always use the smallest type that serves your needs for the long run.
For example, use TINYINT for an attribute that will have a value no larger than 100. TINYINT uses only 1 byte, if you used INT then 4 bytes would be used. However, say you are using an ID field that will grow to over a billion, INT will serve short term needs but you must use BIGINT in this scenario to prepare for the future.
SQL Server 70-461 02-02a
When should you use a fixed data type and when should you use a variable data type?
Consider using a fixed data type if update performance is a priority since the row will not have to physically expand and therefore data shifting isn’t necessary.
A variable type may be preferable if read performance is a priority. The less storage used, the less there is for a query to read, and the faster the query can perform.
SQL Server 70-461 02-02a
If read performance is a priority but the best data type to use is a fixed data type, what can you do to improve performance?
You can use compression.
If you use compression, especially row compression, a fixed data type will be stored like a variable data type, but with lower overhead.
SQL Server 70-461 02-02a
When should you use a Regular character data type?
When your data will only be in English and one other language.
SQL Server 70-461 02-02a
When should you use a Unicode character data type?
If your data is international (many languages) or your application natively works with Unicode.
SQL Server 70-461 02-02a
What are the different storage requirements for Regular vs Unicode character types?
Regular character types use 1 byte of storage per character.
Unicode character types use 2 bytes of storage per character, unless compressed.
Surrogate pairs use 4 bytes of storage.
SQL Server 70-461 02-02a
How can the storage requirements of Unicode data types be mitigated?
By using Unicode compression.
SQL Server 70-461 02-02a
What happens if you don’t specify length for a data type that allows a length designation?
SQL Server will assign a default length. It is therefore best practice to always choose a length for those data types that allow a length specification.
SQL Server 70-461 02-02a