SQL DataTypes
Data Types:In SQL (Structured Query Language), a datatype specifies the type of data that can be stored in a column of a table. It defines the kind of values that a column can hold, such as integers, strings, dates, etc. Each column in a table must have a specific datatype, which helps the database management system (DBMS) understand how to store, validate, and manipulate the data.
CHAR:
Stores fixed-size character data.
Capacity: Up to 255 characters.
Example:
CHAR(10)
Note: Wastes space if not fully utilized.
VARCHAR:
Stores variable-length character data and accepts alphanumeric values.
Capacity varies depending on the database.
Example:
VARCHAR(10)
Efficient use of storage as it only uses what's needed.
VARCHAR2:
Similar to VARCHAR, used in Oracle databases.
Capacity: Up to 2000 characters.
Example:
VARCHAR2(10)
Efficient use of storage, eliminates non-padded information.
NUMBER(p, s):
Represents fixed-point numbers with precision (p) and scale (s).
Example:
NUMBER(5, 2)
for numbers like 123.45.Can store up to 36 digits without precision and scale.
DATE:
Represents date and time.
Standard format: DD-MM-YY.
LONG:
- Used for storing large data (up to 2GB) in a column.
RAW (or Long Raw):
- Used for storing binary data, like images.
Subscribe to my newsletter
Read articles from Pavan Potharaj directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by