Literals Flashcards
What is another name for a literal?
A constant
SQL Server 70-461 02-02a
Why is it important to use the correct form when indicating a literal?
Because otherwise SQL Server will employ implicit conversion, if possible, and this may have an affect on performance.
SQL Server 70-461 02-02a
Give some examples of how the interpretation of a literal may not be what you think intuitively.
The literal1 will always be considered an INT by SQL Server, no matter the context. To have it be BIT instead, you will have to convert explicitly.
The literal 4000000000 is considered NUMERIC. To have it be BIGINT instead you will have to convert explicitly.
SQL Server 70-461 02-02a
How can you force a literal to be of a certain type?
Apply explicit conversion.
SQL Server 70-461 02-02a
What is the proper way to express a regular character literal?
- Put it between single quotes.
- Example: lastname=’Davis’
SQL Server 70-461 03-01
What is the proper way to express a unicode character literal?
- N followed by the literal in single quotes.
- Example: lastname=N’Davis’
SQL Server 70-461 03-01
What is the best way to express a date literal and why?
- The best way is ‘yyyymmdd’. Reason being, it is language-neutral for all date and time types. Meaning regardless of the default language your computer uses (British, American, Japanese) it will be interpreted the same.
- Alternatively you could use the CONVERT or PARSE functions.
SQL Server 70-461 03-01
What date literal formats are language dependant?
- The format ‘02/12/07’ or the format ‘02/12/2007’
- In Britain, this would be December 2, 2007
- In Japan, this would be December 7, 2002
- In America, this would be February 12, 2007
SQL Server 70-461 03-01
Why is it important to express character literals correctly?
If you don’t, implicit conversion may be used and this can hurt performance.
SQL Server 70-461 03-01
What date literal is language-neutral for some data types and language dependant for others?
‘2007-02-12’
This is language-neutral for
- DATE
- DATETIME2
- DATETIMEOFFSET
This is language-dependant for
- DATETIME
- SMALLDATETIME
SQL Server 70-461 03-01