Skip to content
Unit 4 Syllabus Note· Introduction to Database System

Introduction to Database System

Comprehensive exam revision notes for BCA-104N Unit 4 (Structured Query Language (SQL) & Table Management). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.

Introduction to Database System

Structured Query Language (SQL) & Table Management

Core Definitions & Key Concepts

Classify SQL statements into DDL, DML, DCL, and TCL

  • DDL (Data Definition Language): Defines structure (CREATE, ALTER, DROP, TRUNCATE).
  • DML (Data Manipulation Language): Manages data rows (SELECT, INSERT, UPDATE, DELETE).
  • DCL (Data Control Language): Manages permissions (GRANT, REVOKE).
  • TCL (Transaction Control Language): Manages transactions (COMMIT, ROLLBACK, SAVEPOINT).

DROP TABLE and TRUNCATE TABLE

  • DROP TABLE: DDL command that removes both table data and the entire schema definition permanently from the data dictionary.
  • TRUNCATE TABLE: DDL command that deletes all data rows instantaneously while preserving table structure; it cannot be rolled back in most DBMS and resets auto-increment.

The difference between CHAR and VARCHAR data types

  • CHAR(n): Fixed-length character string. If input is shorter than n, it is right-padded with blanks to occupy exactly n bytes.
  • VARCHAR(n): Variable-length character string. Stores only actual characters entered plus 1-2 bytes length prefix, conserving disk space.

List five column integrity constraints in SQL

  1. PRIMARY KEY (Uniquely identifies rows, non-null).
  2. UNIQUE (Ensures unique values, allows nulls).
  3. NOT NULL (Forbids null values).
  4. CHECK (Enforces custom condition/range).
  5. DEFAULT (Supplies fallback default value).
  6. FOREIGN KEY (Enforces referential integrity).

Differentiate WHERE clause from HAVING clause

  • WHERE: Filters individual rows before any grouping or aggregation takes place; cannot contain aggregate functions.
  • HAVING: Filters aggregated groups after GROUP BY execution; explicitly designed for aggregate conditions (e.g., HAVING COUNT(*) > 5).

What is the difference between INNER JOIN and LEFT OUTER JOIN

  • INNER JOIN: Returns only rows having matching keys in both participating tables.
  • LEFT OUTER JOIN: Returns all rows from left table plus matching rows from right table; unmatched right attributes are populated with NULL.

Correlated Subqueries versus Non-Correlated Subqueries

  • Non-Correlated: Subquery executes independently once; its result is passed to outer query.
  • Correlated: Subquery references a column from the outer query row, executing once for every row evaluated by outer query.

What is a View in SQL? Give the syntax to create a view

A View is a virtual table defined by a stored SQL query; it does not store physical data rows itself. Syntax: CREATE VIEW view_name AS SELECT col1, col2 FROM table_name WHERE condition;

Conceptual & Architectural Analysis

SQL Aggregate Functions (COUNT, SUM, AVG, MIN, MAX) with a GROUP BY and HAVING example

Aggregate functions compute a single summary value over a set of rows:

  • COUNT(col): Returns total non-null row count.
  • SUM(col): Returns arithmetic sum of numeric values.
  • AVG(col): Returns arithmetic mean.
  • MIN(col) / MAX(col): Returns minimum or maximum value.

Practical Query Example

Find departments having more than 3 employees and average salary exceeding 50,000:

SQL
1SELECT dept_id, COUNT(*) AS total_employees, AVG(salary) AS avg_salary
2FROM Employee
3WHERE status = 'Active'
4GROUP BY dept_id
5HAVING COUNT(*) > 3 AND AVG(salary) > 50000
6ORDER BY avg_salary DESC;

All types of SQL Joins (Inner, Left, Right, Full, Cross) with Venn diagrams

CODE
1 INNER JOIN LEFT JOIN RIGHT JOIN
2 /----------\ /----------\ /----------\
3 / #### \ / ######## \ / ######## \
4 ( A #### B ) ( A ####### B ) ( A ####### B)
5 \ #### / \ ######## / \ ######## /
6 \----------/ \----------/ \----------/
7 Matched Only All A + Matched B All B + Matched A
  • FULL OUTER JOIN: Returns all rows from both tables; unmatched rows on either side contain NULLs.
  • CROSS JOIN: Cartesian product returning M * N rows pairing every row of table A with every row of table B.

In-Depth Analysis & Implementation

Write comprehensive SQL DDL and DML scripts to create a Normalized Employee Database, enforce all constraints, and solve 8 university exam query patterns

1. DDL Schema Definition with Integrity Constraints

SQL
1CREATE TABLE Department (
2 dept_id INT PRIMARY KEY,
3 dept_name VARCHAR(50) NOT NULL UNIQUE,
4 location VARCHAR(50) DEFAULT 'Bareilly'
5);
6
7CREATE TABLE Employee (
8 emp_id INT PRIMARY KEY,
9 emp_name VARCHAR(50) NOT NULL,
10 email VARCHAR(100) UNIQUE,
11 salary DECIMAL(10, 2) CHECK (salary >= 10000),
12 hire_date DATE NOT NULL,
13 dept_id INT,
14 CONSTRAINT fk_dept FOREIGN KEY (dept_id)
15 REFERENCES Department(dept_id)
16 ON DELETE SET NULL
17 ON UPDATE CASCADE
18);

2. High-Yield University Exam SQL Query Problems

  1. Find employees with salary between 40,000 and 80,000 in 'IT' or 'Finance':
SQL
1SELECT e.emp_id, e.emp_name, e.salary, d.dept_name
2FROM Employee e
3JOIN Department d ON e.dept_id = d.dept_id
4WHERE e.salary BETWEEN 40000 AND 80000
5 AND d.dept_name IN ('IT', 'Finance');
  1. Find the 2nd Highest Salary in the Company (using Subquery):
SQL
1SELECT MAX(salary) AS second_highest_salary
2FROM Employee
3WHERE salary < (SELECT MAX(salary) FROM Employee);
  1. Find employees earning more than the average salary of their own department (Correlated Subquery):
SQL
1SELECT e1.emp_name, e1.salary, e1.dept_id
2FROM Employee e1
3WHERE e1.salary > (
4 SELECT AVG(e2.salary)
5 FROM Employee e2
6 WHERE e2.dept_id = e1.dept_id
7);
  1. Find departments with no assigned employees (Outer Join):
SQL
1SELECT d.dept_id, d.dept_name
2FROM Department d
3LEFT JOIN Employee e ON d.dept_id = e.dept_id
4WHERE e.emp_id IS NULL;

Important Exam Points & Quick Revision

In BCA-104N Unit 4, the university examination always features direct SQL query problems. Master writing syntactically correct JOIN, GROUP BY, HAVING, and nested subqueries (like N-th highest salary).

Your reading progress
0%

100% left on this page — finishing it closes the gap for Structured Query Language (SQL) & Table Management.

Weak topic hint

Structured Query Language (SQL) & Table Management still counts as a weak topic until you finish this note and answer its questions.

Practise this unit
What Should You Do Next?

Test Your Understanding

Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.