Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Java Index Previous

Interview
Next
Resour  
 


Tutorial Posts Questions ces

SQL Data Types Filed Under: SQL


19 Comments

Home » SQL » SQL Data Types

SQL Tutorials
SQL Data Types de ne the type of
1. What is SQL? value that can be stored in a table
2. SQL Data Types column. For example, if we want a
3. SQL Operators column to store only integer values,
then we can de ne it’s data type as
4. SQL Logical
int .
Operators
5. SQL Expressions
6. SQL Keywords Table of Contents [hide] Support Vector Machines in
7. SQL Functions R programming
1 SQL Data Types
8. SQL SELECT
1.1 SQL Data Types important
9. SQL INSERT
points
10. SQL UPDATE
1.2 SQL Numeric Data Types
11. SQL DELETE
1.3 SQL Date and Time Data
12. SQL WHERE
Types
13. SQL DISTINCT
1.4 SQL Character and String
14. SQL ORDER BY
Data Types
15. SQL LIKE
1.5 SQL Unicode Character and
16. SQL IN, NOT IN
String Data Types
17. SQL NULL
1.6 SQL Binary Data Types
18. SQL UNION
1.7 SQL Miscellaneous Data
19. SQL INTERSECT
Types
20. SQL EXCEPT
21. SQL COMMIT
ROLLBACK SQL Data Types
22. SQL Subquery
23. SQL BETWEEN SQL data types can be broadly divided
into following categories.
24. SQL SELECT INTO
25. SQL INSERT INTO
26. SQL LIMIT
27. SQL ALIAS
28. SQL CREATE
DATABASE
29. SQL RENAME
Database
Previous Next  
30. SQL DROP
Database
31. SQL SELECT
Database
32. SQL CREATE Table
33. SQL DROP Table
34. SQL ALTER Table
35. SQL TRUNCATE
Table
36. SQL Copy Table
37. SQL Interview
Questions
38. PL/SQL Interview
Questions
1. Numeric data types such as int,
tinyint, bigint, oat, real etc.

2. Date and Time data types such as


Date, Time, Datetime etc.

3. Character and String data types


such as char, varchar, text etc.

4. Unicode character string data


types, for example nchar,
nvarchar, ntext etc.

5. Binary data types such as binary,


varbinary etc.

6. Miscellaneous data types – clob,


blob, xml, cursor, table etc.

SQL Data Types


important points

cNot all data types are supported by


hevery relational database vendors.
For example, Oracle database
edoesn’t support DATETIME and
MySQL doesn’t support CLOB data
vtype. So while designing database Previous Next  
rschema and writing sql queries,
omake sure to check if the data
ntypes are supported or not.
_
c
rData types listed here doesn’t
include all the data types, these are
h
ithe most popularly used data
e
gtypes. Some relational database
v
hvendors have their own data types
r
tthat might be not listed here. For
example, Microsoft SQL Server has
o money and smallmoney data
ntypes but since it’s not supported
_by other popular database vendors,
rit’s not listed here.
i
gEvery relational database vendor
c
hhas it’s own maximum size limit for
different data types, you don’t need
tto remember the limit. Idea is to
e
vhave the knowledge of what data
rtype to be used in a speci c
scenario.
o
n
_
Let’s look into different categories of
r
sql data types in detail.
i
g
SQL
h Numeric Data
Types
t

Datatype From To

bit 0 1

tinyint 0 255

smallint -32,768 32,767

int -2,147,483,648 2,147,483,647

-9,223,372,036, 9,223,372,036,
bigint
854,775,808 854,775,807

decimal -10^38 +1 10^38 -1

numeric -10^38 +1 10^38 -1

float -1.79E + 308 1.79E + 308

real -3.40E + 38 3.40E + 38

SQL Date and Time


Data Types
Datatype Description
DATE Stores date in the format
YYYY-MM-DD
Previous Next  
Stores time in the format
TIME
HH:MI:SS

Stores date and time


DATETIME information in the format
YYYY-MM-DD HH:MI:SS

Stores number of seconds


passed since the Unix
TIMESTAMP
epoch (‘1970-01-01
00:00:00’ UTC)

Stores year in 2 digit or 4


digit format. Range 1901 to
YEAR 2155 in 4-digit format.
Range 70 to 69,
representing 1970 to 2069.

SQL Character and


String Data Types
Datatype Description

Fixed length with


CHAR maximum length of
8,000 characters

Variable length storage


VARCHAR with maximum length
of 8,000 characters

Variable length storage


with provided max
VARCHAR(max)
characters, not
supported in MySQL

Variable length storage


TEXT with maximum size of
2GB data

Note that all the above data types are


for character stream, they should not
be used with unicode data.

SQL Unicode
Character and String
Data Types
Datatype Description

Fixed length with


NCHAR maximum length of
4,000 characters

Variable length
storage with
NVARCHAR
maximum length of
4,000 characters

NVARCHAR(max) Variable length


storage with provided
max characters
Previous Next  
Variable length
storage with
NTEXT
maximum size of 1GB
data

Note that above data types are not


supported in MySQL database.

SQL Binary Data


Types
Datatype Description

Fixed length with


BINARY maximum length of
8,000 bytes

Variable length
storage with
VARBINARY
maximum length of
8,000 bytes

Variable length
VARBINARY(max) storage with provided
max bytes

Variable length
storage with
IMAGE
maximum size of
2GB binary data

SQL Miscellaneous
Data Types
Datatype Description

Character large objets that can


CLOB
hold up to 2GB

BLOB For binary large objects

XML for storing xml data

JSON for storing JSON data


That’s all for a quick roundup on SQL
data types. Previous Next  
Reference: Oracle Database Data
Types, mySQL Data Types

Support Vector Machines in R programming

SQL

PREV

SQL Interview Questions and


Answers

NEXT

Pankaj
I love Open
Source
technologies Follow Author
and writing
about my
experience
about them
is my
passion.

Comments
September
Bhargav 3, 2020 at 11:04 am
says:
Thank you
Reply Previous Next  

ezhil says:
August 6, 2020 at 6:56 pm

what is the data type for


CSE5001
Reply

Keerthi
February 27, says:
2021 at 10:33 am

Varchar
Reply

GowthamiJune
says:
3, 2020 at 5:50 am

How to sort column


VALUES in ASC order a
column
Reply

Pankaj says:
June 4, 2020 at 3:36 am

Use “Order by ASC”


clause at the end of
the select query.Reply

YOurBRo says:
June 26, 2020 at 11:49 pm

just use ORDER BY at


last no need to write
ASC
Reply

prasanna lakshmi
December 2, 2019 says:
at 5:41 am

some columns like salary


will not take int ,smallint
data types .it takes only
char and varchar why???
Reply

Ken says:
December 19, 2019 at 12:32 pm

If you are using a


decimal point, oat is
the correct data Reply
type.

Sylvester Marshall
October says:
4, 2019 at 9:27 pm

Hi Pankaj,
The tutorial contents and
the graphical presentation
are absolutely fantastic.
The amount of efforts you
have taken is highly Previous Next  
appreciated and I would
like to express my sincere
gratitude. God Bless you
dear !! Reply

Samuel
October says:
13, 2020 at 12:22 am

Thank you for this


useful material. Be
blessed always
I came a little late but
still have bene ted.
Reply

Rajaram says:
August 12, 2019 at 10:52 am

Good Evening Shri.Pankaj


Sir,
very very useful &
bene cial of your SQL
lecture.
Great thanks full for your
Guide in SQL study
materials.
by Rajaram Reply

Saurabh Rawat says:


July 24, 2019 at 7:00 am

Hello everyone here


I am new at sql
How can i insert data into a
table which contain both
Character and letter (For
eg A001)
Which datatype should i
use here. Please let me
know
Reply

Pankaj says:
July 24, 2019 at 9:11 pm

Use varchar or
varchar2 for string
data.
Reply

Ajaykumar
December says
5, 2019 at 9:49 pm
Singh :
use ‘varchar(length)’
datatype Reply
Mr SQL says:
July 9, 2019 at 5:21 am Previous Next  
Type BIT is not a numeric
data type, its binary. Also it
is no longer part of SQL
standard. So better to
remove it.
Type YEAR does not exist
in SQL standard. Also
never use year numbers
with only 2 digits
(remember year2k bug?)
You miss the type
BOOLEAN which can have
values true or false. It is
fundamentally different
from BIT.
You miss the type
INTERVAL of which there
are 2 basic ones:
INTERVAL SECONDS (can
include fractions) and
INTERVAL MONTHS.
Type TEXT and NTEXT are
old synonyms for CLOB, so
use CLOB (or CHARACTER
LARGE OBJECT).
Type IMAGE is an old
synonym for BLOB, so use
BLOB (or BINARY LARGE
OBJECT). Reply

sadiqullah says:
April 13, 2019 at 10:52 pm

thank’s so much
Reply

Blabla says:
March 5, 2019 at 4:57 am

Very good my son..


God bless you
Reply

Shirajul says:
January 22, 2019 at 10:16 am

Hello,
Is it possible to enter an
Array for a value in a table?
Is there an ARRAY column
type?
Kind Regards, Reply
Sew
Marchsays:
26, 2019 at 3:52 am Previous Next  
But why?? I think
better idea is create
another table and
make refferenceReply

Leave a Reply
Your email address will not be
published. Required elds are marked
*

Comment

Name * Email *

Post Comment

Newsle er for You

Enter your email address here... 


Previous Next  

Most Popular Favorite Sites

JournalDev is one of the most


Java / Java EE AskPython
popular websites for Java, Python, Tutorials

Android, and related technical BloggerTipsAndTricks


Core Java Tutorial
articles. Our tutorials are regularly
GoLangDocs
updated, error-free, and complete. Python Tutorials

Every month millions of developers LinuxForDevices


Java Interview
like you visit JournalDev to read our Questions Mkyong
tutorials.
Core Java Interview VM-Help
Questions
JournalDev was founded by Pankaj
WP-Design
Kumar in 2010 to share his Java Design Pa erns

experience and learnings with the


Spring Tutorial
whole world. He loves Open source
technologies and writing on
JournalDev has become his
passion.

© 2020 · Privacy Policy · Terms and Conditions · Contact Us · About · Part of JournalDev IT Services Private Limited
 

You might also like