XII IP Notes Database
XII IP Notes Database
Differences
1) DDL vs. DML
Feature DDL (Data Definition Language) DML (Data Manipulation Language)
Defines database structure (tables, schemas, Manipulates existing data (insert, update, delete,
Purpose
constraints). retrieve).
Commands CREATE, ALTER, DROP, TRUNCATE SELECT, INSERT, UPDATE, DELETE
Effect on Data Changes table structure, not data. Modifies data within tables.
Rollback
Generally not possible (except some cases). Supports ROLLBACK to undo changes.
Option
2) WHERE vs. HAVING Clause
Feature WHERE Clause HAVING Clause
Filters individual rows before
Purpose Filters aggregated groups after using GROUP BY.
aggregation.
SELECT with aggregate functions (SUM, AVG,
Used With SELECT, UPDATE, DELETE
etc.).
SELECT dept, AVG(salary) FROM
SELECT * FROM students WHERE
Example employees GROUP BY dept HAVING
age > 18;
AVG(salary) > 50000;
3) Single Row Functions vs. Multi Row Functions
Feature Single Row Functions Multi Row Functions
Operates on individual rows and returns one result per Operates on a set of rows and returns a single
Definition
row. value.
Examples UPPER(), LOWER(), LENGTH(), ROUND(), ABS() COUNT(), SUM(), AVG(), MAX(), MIN()
Use
Formatting data, manipulating values within a row. Aggregating data across multiple rows.
Cases
4) DELETE vs. DROP Commands
Feature DELETE DROP
Purpose Removes specific records from a table. Removes an entire table from the database.
Effect on Table Table structure remains intact. Table and its data are permanently removed.
Rollback Option Possible with ROLLBACK. Not possible once executed.
Example DELETE FROM students WHERE age < 18; DROP TABLE students;
5) Primary Key vs. Foreign Key vs. Unique Key
Feature Primary Key Foreign Key Unique Key
Uniquely identifies records Links one table to another using a Ensures uniqueness but allows
Purpose
in a table. reference. NULL values.
Number Can have multiple foreign keys
Only one per table. Multiple unique keys per table.
Allowed per table.
NULL Yes (if not explicitly set to NOT
No Yes
Allowed? NULL).
6) Candidate Key vs. Primary Key vs. Alternate Key
Feature Candidate Key Primary Key Alternate Key
A column (or set of columns) that The selected candidate key used Remaining candidate keys after
Definition
can uniquely identify each row. to uniquely identify rows. choosing a primary key.
Number Multiple candidate keys exist in a Depends on the number of
Only one primary key per table.
Allowed table. candidate keys.
(AdmNo, Aadhaar Number) in a AdmNo (chosen as primary Aadhaar Number (alternate
Example
student table. key). key).
7) CHAR vs. VARCHAR
Feature CHAR VARCHAR
Definition Fixed-length character storage. Variable-length character storage.
Storage Uses space dynamically, adjusting based on
Uses allocated space even if characters are fewer.
Efficiency stored characters.
Best for short, fixed-length strings (e.g., country Best for storing variable-length data (e.g.,
Use Case
codes, status values). names, addresses).
VARCHAR(10) only stores exact character
Example CHAR(10) always reserves space for 10 characters.
count.