SQL DataTypes

Pavan PotharajPavan Potharaj
1 min read

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.

  1. CHAR:

    • Stores fixed-size character data.

    • Capacity: Up to 255 characters.

    • Example: CHAR(10)

    • Note: Wastes space if not fully utilized.

  2. 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.

  3. VARCHAR2:

    • Similar to VARCHAR, used in Oracle databases.

    • Capacity: Up to 2000 characters.

    • Example: VARCHAR2(10)

    • Efficient use of storage, eliminates non-padded information.

  4. 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.

  5. DATE:

    • Represents date and time.

    • Standard format: DD-MM-YY.

  6. LONG:

    • Used for storing large data (up to 2GB) in a column.
  7. RAW (or Long Raw):

    • Used for storing binary data, like images.
1
Subscribe to my newsletter

Read articles from Pavan Potharaj directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pavan Potharaj
Pavan Potharaj