Computer Science

Introduction to SQL and Data Types Class 12 CBSE (083): SQL, DDL, DML and SQL Data Types

Class 12 · Computer Science

Introduction to SQL and Data Types (CBSE Class 12 Computer Science - 083)

Modern organizations store enormous amounts of data in databases. To create, manage, retrieve, and manipulate this data efficiently, we use Structured Query Language (SQL). SQL is the standard language used to communicate with Relational Database Management Systems (RDBMS) such as MySQL, Oracle, SQL Server, PostgreSQL, and SQLite.

Learning Objectives

  • Understand the concept of SQL.
  • Learn the purpose and importance of SQL.
  • Study the categories of SQL commands.
  • Understand Data Definition Language (DDL).
  • Understand Data Manipulation Language (DML).
  • Learn commonly used SQL data types.

What is SQL?

SQL (Structured Query Language) is a standard programming language used to create, access, retrieve, modify, and manage data stored in relational databases.

Definition: SQL (Structured Query Language) is the standard language used for communicating with relational database management systems (RDBMS).

Why is SQL Used?

SQL allows users to perform various database operations efficiently.

  • Create databases.
  • Create tables.
  • Insert data.
  • Retrieve data.
  • Update records.
  • Delete records.
  • Modify database structure.
  • Control data access.

Features of SQL

  • Simple and easy to learn.
  • Standard language supported by almost all RDBMS.
  • Supports large databases.
  • Allows efficient data retrieval.
  • Supports data security and integrity.
  • Uses simple English-like commands.

Popular Database Management Systems Using SQL

Database Developed By
MySQL Oracle Corporation
Oracle Database Oracle Corporation
Microsoft SQL Server Microsoft
PostgreSQL PostgreSQL Global Development Group
SQLite SQLite Consortium

Categories of SQL Commands

SQL commands are grouped into different categories based on their purpose.

According to the CBSE Class 12 syllabus, the two major categories are:

  1. Data Definition Language (DDL)
  2. Data Manipulation Language (DML)

1. Data Definition Language (DDL)

Data Definition Language (DDL) consists of SQL commands used to create and modify the structure of database objects such as databases and tables.

Remember: DDL changes the structure of the database.

Common DDL Commands

Command Purpose
CREATE Creates a database or table.
ALTER Modifies the structure of a table.
DROP Deletes a database or table.
DESCRIBE (DESC) Displays the table structure.
SHOW Displays databases or tables.

Examples of DDL Commands

Create a Database


CREATE DATABASE School;

Create a Table


CREATE TABLE Student
(
    StudentID INT,
    Name VARCHAR(30),
    Marks INT
);

Drop a Table


DROP TABLE Student;

2. Data Manipulation Language (DML)

Data Manipulation Language (DML) consists of commands used to insert, retrieve, update, and delete data stored in database tables.

Remember: DML changes the data stored inside the tables.

Common DML Commands

Command Purpose
INSERT Adds new records.
SELECT Retrieves records.
UPDATE Modifies existing records.
DELETE Removes records.

Examples of DML Commands

Insert Data


INSERT INTO Student
VALUES
(101,'Riya',95);

Retrieve Data


SELECT * FROM Student;

Update Data


UPDATE Student
SET Marks=98
WHERE StudentID=101;

Delete Data


DELETE FROM Student
WHERE StudentID=101;

Difference Between DDL and DML

DDL DML
Defines database structure. Manipulates table data.
Works on databases and tables. Works on records.
Examples: CREATE, ALTER, DROP. Examples: INSERT, UPDATE, DELETE, SELECT.
Changes the structure. Changes the data.

SQL Data Types

A Data Type specifies the kind of value that can be stored in a table column. Choosing the correct data type improves storage efficiency and data accuracy.


1. CHAR(n)

The CHAR(n) data type stores fixed-length character strings.

Characteristics

  • Fixed length.
  • If the entered value is shorter, spaces are added automatically.
  • Suitable for fixed-size data.

Syntax


CHAR(10)

Example


Gender CHAR(1)
CountryCode CHAR(3)

2. VARCHAR(n)

The VARCHAR(n) data type stores variable-length character strings.

Characteristics

  • Stores only the required characters.
  • Saves storage space.
  • Most commonly used text data type.

Syntax


VARCHAR(50)

Example


Name VARCHAR(30)
Address VARCHAR(100)

Difference Between CHAR and VARCHAR

CHAR VARCHAR
Fixed length. Variable length.
Consumes fixed storage. Consumes only required storage.
Suitable for fixed-size values. Suitable for names, addresses, etc.

3. INT

The INT data type stores whole numbers without decimal values.

Examples

  • Roll Number
  • Age
  • Quantity
  • Marks

Syntax


Age INT

4. FLOAT

The FLOAT data type stores decimal numbers.

Examples

  • Percentage
  • Salary
  • Height
  • Weight

Syntax


Salary FLOAT

5. DATE

The DATE data type stores calendar dates.

Standard Format


YYYY-MM-DD

Example


2026-08-15

Summary of SQL Data Types

Data Type Stores Example
CHAR(n) Fixed-length text CHAR(5)
VARCHAR(n) Variable-length text VARCHAR(50)
INT Whole numbers 101
FLOAT Decimal numbers 87.75
DATE Date values 2026-08-15

Common Theory Mistakes

  • Confusing DDL with DML commands.
  • Using CHAR for variable-length text.
  • Using VARCHAR for fixed-length codes such as gender or country code.
  • Storing decimal values in INT columns.
  • Writing DATE values in incorrect formats.

Exam Tips

  • Remember: DDL defines the structure, whereas DML manipulates the data.
  • Know the difference between CHAR and VARCHAR.
  • Use INT for whole numbers and FLOAT for decimal values.
  • DATE values are generally stored in the format YYYY-MM-DD.
  • Practice writing simple SQL commands without syntax errors.

Frequently Asked Questions (FAQs)

1. What is SQL?

SQL (Structured Query Language) is the standard language used to create, manage, and manipulate relational databases.

2. What is the difference between DDL and DML?

DDL commands define and modify the database structure, whereas DML commands are used to insert, retrieve, update, and delete data.

3. What is the difference between CHAR and VARCHAR?

CHAR stores fixed-length character data, while VARCHAR stores variable-length character data and uses storage more efficiently.

4. Which SQL data type is used to store decimal numbers?

The FLOAT data type is used to store decimal numbers.

5. Which SQL data type is used to store dates?

The DATE data type is used to store calendar dates, usually in the format YYYY-MM-DD.


Summary

  • SQL is the standard language for managing relational databases.
  • DDL commands create and modify database structures.
  • DML commands manipulate the data stored in tables.
  • CHAR stores fixed-length text, while VARCHAR stores variable-length text.
  • INT stores whole numbers, FLOAT stores decimal values, and DATE stores calendar dates.
  • Understanding SQL basics and data types is essential before learning advanced SQL commands.