SQL data types and literals
By Mohit Bisht & Moksh Sharma
\
SQL: LITERALS
• The terms literal and constant value are synonymous and
refer to a fixed data value. For example, 'JACK', 'BLUE
ISLAND', and '101' are all character literals; 5001 is a
numeric literal.
TYPES OF SQL LITERALS
• String Literals
• Integer Literals
• Decimal Literals
• Datetime Literals
STRING LITERALS
• String literals are always surrounded by single quotes (‘).
• For example:
'TechOnTheNet.com’
'This is a literal’
'XYZ’
'123'
DECIMAL LITERALS
• Decimal literals can be either positive numbers or negative
numbers and contain decimals. If you do not specify a sign,
then a positive number is assumed. Here are some
examples of valid decimal literals:
• Examples:-
24.7
+24.7
-24.7
INTEGER LITERALS
• Integer literals can be either positive numbers or negative
numbers, but do not contain decimals. If you do not specify
a sign, then a positive number is assumed. Here are some
examples of valid integer literals
• Examples:-
536
+536
-536
DATETIME LITERALS
• Datetime literals are character representations of datetime
values that are enclosed in single quotes. Here are some
examples of valid datetime literals:
• Examples:-
'April 30, 2015’
'2015/04/30’
'2015/04/30 08:34:25'
WHAT IS DATA TYPE
• A data type specifies a particular types of data, such as
integer floating-point,Boolean,etc
• A data type also specifies the possible values for that types,
the operation that can be performed on that type and the
way the values of that types are stored.
• SQL Data Types define the type of value that can be stored
in a table column. For example, if we want a column to
store only integer values, then we can define it’s data type
as
MAIN CATOGORIES OF DATA TYPES
• NUMERIC TYPES
• DATE AND TIME TYPES
• STRING TYPE
NUMERIC DATA TYPES
• INTEGERS
• SMALLINT
• DECIMAL
• NUMERIC
• FLOAT
DECIMAL DATA TYPE
• Decimal(5,2) be able to store any value with five digit and
2 decimals
• Value range will be -999.99 to 999.99
• Decimal(M) is equivalent to decimal(M,0)
STORAGE AND RANGE OF DATA TYPES
Date and Time Types
STRING TYPE IN SQL
• Char
• Varchar
• Binary
• VAR Binary
Thankyou