Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - What Is a Constant or Literal

By: FYIcenter.com

(Continued from previous topic...)

What Is a Constant or Literal?

A constant, or literal, is a symbol that represents a specific value of a specific data type. Constants or literals are used commonly as the default values for table columns, variables, and parameters. The format of constant or literal depends on the data type of the value it represents. There are x formats used to specify literals in SQL Server:

  • Integer Number Literals - Strings of numbers prefixed with (+/-) as the sign if needed. They are used for integer data types. For example: -2255.
  • Decimal Number Literals - Strings of numbers with a single decimal point and an optional prefix sign (+/-). They are used for DECIMAL data type. For example: 1894.1204.
  • Floating Point Number Literals - Numeric values represented in the scientific notation. They are used for FLOAT data type. For example: 9.22337e+010.
  • Character String Literals - Strings of characters enclosed in single quotes. They are used for character string data types. . For example: 'Welcome to FYIcenter.com!'.
  • Unicode Character String Literals - Strings of Unicode characters enclosed in single quotes with a prefix of (N). They are used for Unicode character string data types. For example: N'Welcome to FYIcenter.com'.
  • Binary String Literals - Strings of bytes expressed in HEX numbers and prefixed with (0x). They are used for binary string data types. For example: '0x69048AEFDD010E'.
  • Date and Time Literals - Data and time values expressed in several popular formats and enclosed in single quotes ('). They are used for data and time data types. For example: '2007-05-19 22:55:07.233'.
  • Money Literals - Strings of numbers with a single decimal point with a prefix of ($) and optional sign (+/-). They are used for money data types. For example: $542023.14.

(Continued on next topic...)

  1. What Is a Constant or Literal?
  2. How To Write Character String Constants or Literals?
  3. What Is a Collation?
  4. How To Specify the Collation for a Character Data Type?
  5. What Happens If Strings Are Casted into Wrong Code Pages?
  6. How To Find Out What Is the Default Collation in a Database?
  7. How Fixed Length Strings Are Truncated and Padded?
  8. How To Enter Unicode Character String Literals?
  9. How To Enter Binary String Literals?
  10. How To Enter Date and Time Literals?
  11. Why I Can Not Enter 0.001 Second in Date and Time Literals?
  12. What Happens If Date-Only Values Are Provided as Date and Time Literals?
  13. What Happens If Time-Only Values Are Provided as Date and Time Literals?
  14. What Are Out-of-Range Errors with Date and Time Literals?
  15. What Happens If an Integer Is Too Big for INT Date Type?
  16. How Extra Digits Are Handled with NUMERIC Data Type Literals?
  17. How REAL and FLOAT Literal Values Are Rounded?
  18. What Are the Underflow and Overflow Behaviors on FLOAT Literals?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...