SQL Datatypes
SQL Data Type is an attribute that specifies the type of data of any object.
Every column is required to have a name and data type in the database table.
You can use these data types while creating your tables. You can choose a data
type for a table column based on your requirement. SQL offers six categories
of data types for your use which are listed below
1. Binary Datatypes
There are Three types of binary Datatypes which are given below:
binary |
It has a maximum length of 8000 bytes. It contains fixed-length binary data.
|
varbinary |
It has a maximum length of 8000 bytes. It contains variable-length binary data..
|
image |
It has a maximum length of 2,147,483,647 bytes. It contains variable-length binary data.
|
2. Approximate Numeric Datatype
The subtypes are given below:
float |
Range from -1.79E + 308 to 1.79E + 308. It is used to specify a floating-point value e.g. 6.2, 2.9 etc.
|
real |
Range from -3.40e + 38 to 3.40e + 38. It specifies a single precision floating point number.
|
3. Exact Numeric Datatype
The subtypes are given below:
int |
It is used to specify an integer value.
|
smallint |
It is used to specify small integer value.
|
bit |
It has the number of bits to store.
|
decimal |
It specifies a numeric value that can have a decimal number.
|
numeric |
It is used to specify a numeric value.
|
4. Character String Datatype
The subtypes are given below:
char |
It has a maximum length of 8000 characters. It contains Fixed-length non-unicode characters.
|
varchar |
It has a maximum length of 8000 characters. It contains variable-length non-unicode characters.
|
text |
It has a maximum length of 2,147,483,647 characters. It contains variable-length non-unicode characters.
|
5. Date and time Datatypes
The subtypes are given below:
date |
It is used to store the year, month, and days value.
|
time |
It is used to store the hour, minute, and second values.
|
timestamp |
It stores the year, month, day, hour, minute, and the second value.
|
SQL Operators
SQL Data Type is an attribute that specifies the type of data of any object.
Every column is required to have a name and data type in the database table.
You can use these data types while creating your tables. You can choose a data
type for a table column based on your requirement. SQL offers six categories
of data types for your use which are listed below
1. SQL Arithmetic Operators
Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and 'b' contains 10.
+ |
It adds the value of both operands. i.e. a+b will give 30
|
- |
It is used to subtract the right-hand operand from the left-hand operand. i.e. a-b will give 10
|
* |
It is used to multiply the value of both operands. i.e. a*b will give 200
|
/ |
It is used to divide the left-hand operand by the right-hand operand. i.e. a/b will give 2
|
% |
It is used to divide the left-hand operand by the right-hand operand and returns reminder. i.e a%b will give 0
|
2. SQL Comparison Operators
Let's assume 'variable a' and 'variable b'. Here, 'a' contains 20 and 'b' contains 10.
= |
It checks if two operands values are equal or not, if the values are queal then condition becomes true. Example: (a=b) is not true
|
!= |
It checks if two operands values are equal or not, if values are not equal, then condition becomes true. Example: (a!=b) is true
|
<> |
It checks if two operands values are equal or not, if values are not equal then condition becomes true. Example: (a<>b) is true
|
> |
It checks if the left operand value is greater than right operand value, if yes then condition becomes true. Example: (a>b) is not true
|
< |
It checks if the left operand value is less than right operand value, if yes then condition becomes true. Example: (a
|
>= |
It checks if the left operand value is greater than or equal to the right operand value, if yes then condition becomes true. Example: (a>=b) is not true
|
<= |
It checks if the left operand value is less than or equal to the right operand value, if yes then condition becomes true. Example: (a<=b) is true
|
!< |
It checks if the left operand value is not less than the right operand value, if yes then condition becomes true. Example: (a!=b) is not true
|
!>< |
It checks if the left operand value is not greater than the right operand value, if yes then condition becomes true Example: (a!>b) is true
|
3. SQL Logical Operators
There is the list of logical operator used in SQL:
ALL |
It compares a value to all values in another value set.
|
AND |
It allows the existence of multiple conditions in an SQL statement.
|
ANY |
It compares the values in the list according to the condition.
|
BETWEEN |
It is used to search for values that are within a set of values.
|
IN |
It compares a value to that specified list value.
|
NOT |
It reverses the meaning of any logical operator.
|
OR |
It combines multiple conditions in SQL statements.
|
EXISTS |
It is used to search for the presence of a row in a specified table.
|
LIKE |
It compares a value to similar values using wildcard operator.
|