Literals Flashcards

1
Q

What is another name for a literal?

A

A constant

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is it important to use the correct form when indicating a literal?

A

Because otherwise SQL Server will employ implicit conversion, if possible, and this may have an affect on performance.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give some examples of how the interpretation of a literal may not be what you think intuitively.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you force a literal to be of a certain type?

A

Apply explicit conversion.

SQL Server 70-461 02-02a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the proper way to express a regular character literal?

A
  • Put it between single quotes.
  • Example: lastname=’Davis’

SQL Server 70-461 03-01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the proper way to express a unicode character literal?

A
  • N followed by the literal in single quotes.
  • Example: lastname=N’Davis’

SQL Server 70-461 03-01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the best way to express a date literal and why?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What date literal formats are language dependant?

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is it important to express character literals correctly?

A

If you don’t, implicit conversion may be used and this can hurt performance.

SQL Server 70-461 03-01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What date literal is language-neutral for some data types and language dependant for others?

A

‘2007-02-12’

This is language-neutral for
- DATE
- DATETIME2
- DATETIMEOFFSET

This is language-dependant for
- DATETIME
- SMALLDATETIME

SQL Server 70-461 03-01

How well did you know this?
1
Not at all
2
3
4
5
Perfectly