TutorialStudyMite

Datatypes and Operators

SSoumya Shaw7 min read
Beginner friendly

Track completion, mastery, and revision.

What is a Datatype?

Datatypes are memory element that holds some particular data defined/entered by the User.

The need for different datatypes is to ensure the efficiency of memory usage with respect to the data to be stored.

For example, for storing character elements character (not a keyword) datatypes can be used and for integers, their respective datatypes are used.

There are 5 major categories of data types that can be used to define the type of input.

DatatypeFromTo
bigint-9,223,372,036,854,775,8089,223,372,036,854,775,807
int-2,147,483,6482,147,483,647
smallint-32.76832,767
tinyint0255
bit01
decimal-10^38+110^38-1
numeric-10^38+110^38-1
money-922,337,203,685,477.5808922,337,203,685,477.5807
smallmoney-214,748.3648214,748.3647
float-1.79E + 3081.79E + 308
real-3.40E + 383.40E + 38
datetimeJan 1, 1753Dec 31, 9999
smalldatetimeJan 1, 1900Jun 6, 2079
dateStores a data in the form July 5, 2000
timeStores a time in the form 8:30 P.M.

Datatype Description
charMaximum length of 8000 characters (Fixed length)
varcharMaximum of 8000 characters (Variable length)
varchar(max)Max length of 2E+31 characters (Variable length)
textVariable length with a max length of 2,147,483,647
ncharMaximum length of 4000 characters (Fixed length)
nvarcharMaximum of 4000 characters (Variable length)
nvarchar(max)Max length of 2E+31 characters (Variable length)
ntextMax length of 1,073,741,823 characters
binaryMaximum length of 8000 bytes (Fixed length)
varbinaryMaximum of 8000 bytes (Variable length)
varbinary(max)Max length of 2E+31 bytes (Variable length)
imageMax length of 2,147,483,647 bytes (Variable length)

At the same time, the console supports the mathematical/relational equations that help us to determine certain outcomes and workflow.

OperatorUseExampleResult
Arithmetic
+Adds the two numbersSELECT 17 + 5;22
Subtracts the two numbersSELECT 17 – 5;12
*Multiplies the two numbersSELECT 17 * 5;85
/Divides the number two numbers and rounds off to greatest integer of the resultSELECT 17 / 5;3
%Gives the remainder after divisionSELECT 17 % 5;2
Bitwise
&Bitwise AND
|Bitwise OR
^Bitwise XOR
Comparison
=Equal toSELECT * FROM Students WHERE Marks = 50;Students with marks 50
>Greater thanSELECT * FROM Students WHERE Marks > 33;Students with marks more than 33
<Less thanSELECT * FROM Students WHERE Marks <90;Students with marks less than 90
>=Greater than or equal toSELECT * FROM Students WHERE Marks >= 67;Students with marks greater than or equal to 67
<=Less than or equal toSELECT * FROM Students WHERE Marks <= 30;Students with marks less than or equal to 30
<>Not equal toSELECT * FROM Students WHERE Marks = 50;Students with marks 50
Compound
+=Add Equals
-=Subtract Equals
*=Multiply Equals
/=Divide Equals
%=Modulo Equals
&=Bitwise AND Equals
^-=Bitwise Exclusive Equals
|*=Bitwise OR Equals
Logical
ALLTRUE if all subquery value meets the condition
ANDTRUE if all statements separated by AND is TRUE
ANYTRUE if any of the subquery value meets the condition
BETWEENTRUE if the operand is within the range of comparisons
EXISTSTRUE if the subquery returns one or more records
INTRUE if the operand is equal to one of a list of expressions
LIKETRUE if the operand matches a pattern
NOTDisplays a record if the condition is NOT TRUE
ORTRUE if any of the conditions separated by OR is TRUE
SOMETRUE if any of the subquery values meet the condition

Finished reading?

Was this helpful?

Your feedback shapes better tutorials for everyone.