Syntax Recap — DBMS
14 topic(s) — definitions, syntax, and examples.
Definition
Data Definition Language (DDL) commands are SQL statements used to build, alter, and delete database structures such as tables, schemas, and indices.
Purpose
Used by database administrators and developers to define schema blueprints and modify structure without altering the data engine.
General Syntax
Example
Creates a relational table `Supplier`, alters it by adding `state`, drops `city`, and renames the table to `sup`.
Definition
Constraints are rules enforced on data columns to ensure the accuracy, uniqueness, validity, and referential integrity of data stored in relational tables.
Purpose
Prevents invalid data entry, preserves relational relationships between tables, and guarantees domain rules.
General Syntax
Example
Defines primary keys, unique part names, positive price check constraints, foreign key references with cascade deletion, and default quantity.
Definition
Data Manipulation Language (DML) manages data stored within database tables, allowing insertion, retrieval, modification, and deletion of tuples.
Purpose
Enables application programming logic to perform CRUD (Create, Read, Update, Delete) transactions against relational tables.
General Syntax
Example
Inserts a new tuple into `Supplier`, updates city conditionally for 'Vandana', queries suppliers living in 'Delhi', and deletes by primary key.
Definition
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column using wildcards: `%` (zero or more characters) and `_` (exactly one character).
Purpose
Enables flexible textual searches, such as finding names starting with a letter, ending with a letter, or containing a substring.
General Syntax
Example
`%lk%` finds names containing 'lk'; `_R%` matches strings where 'R' is the 2nd character; `V%A` matches names beginning with 'V' and ending with 'A'.
Definition
Aggregate functions calculate a single summary result from a set of values in a column, automatically ignoring NULL values (except `COUNT(*)`).
Purpose
Used for statistical summaries, business reporting, and financial metric calculations.
General Syntax
Example
Calculates minimum, maximum, average, total sum, and total count across records, and computes average price of parts supplied by 'Mike'.
Definition
The GROUP BY clause groups rows sharing the same values in specified columns into summary rows. The HAVING clause filters grouped records after aggregation.
Purpose
Used to calculate aggregated values per category, department, branch, or color, and filter groups based on aggregate conditions.
General Syntax
Example
Groups parts by color to sum prices per color, and groups suppliers by branch to find branches having strictly more than 2 suppliers.
Definition
The ORDER BY clause sorts the result-set in ascending (ASC, default) or descending (DESC) order based on one or multiple columns.
Purpose
Ensures query output is presented in a readable, predictable, and ranked sequence for end-users.
General Syntax
Example
Sorts output primarily alphabetically by part name (`ASC`) and secondary ties by price in descending order (`DESC`).
Definition
Joins combine rows from two or more tables based on a related column between them (matching primary and foreign keys).
Purpose
Essential for querying normalized relational schemas where entity details reside in separate tables.
General Syntax
Example
Demonstrates Inner Join to fetch matching records and Left Join to retain all left-table rows (even if no matching supply record exists).
Definition
Set operators combine the results of two or more SELECT queries into a single result set. Queries must be union-compatible (same number of columns and compatible datatypes).
Purpose
Used for mathematical set union, intersection, difference, and Cartesian product across datasets.
General Syntax
Example
Calculates set difference using EXCEPT to identify unsupplied parts, and filters parts using `NOT IN` with sorting.
Definition
TCL commands manage database transactions to maintain ACID properties (Atomicity, Consistency, Isolation, Durability).
Purpose
Allows developers to group multiple SQL operations into an atomic unit that can be permanently saved or rolled back on error.
General Syntax
Example
Starts a transaction, establishes savepoints, performs rollback to `sp1` to undo subsequent changes, and commits the valid state.
Definition
Window functions perform calculations across a set of table rows related to the current row without collapsing rows into a single summary like GROUP BY.
Purpose
Used for ranking, computing moving averages, finding Nth highest values, and running totals.
General Syntax
Example
Uses `DENSE_RANK()` over descending salary to rank employees and select the 5th highest salary earner.
Definition
Recursive Common Table Expressions (CTEs) iterate over hierarchical data such as organizational charts, bill-of-materials, or graph networks.
Purpose
Enables traversal of parent-child relationships, hierarchy depth levels, and breadth-first / depth-first tree paths in SQL.
General Syntax
Example
Recursively traverses employee-manager relationships, calculating level depth and concatenated hierarchy path string.
Definition
MongoDB is a NoSQL document-oriented database storing BSON JSON-like documents. CRUD operations interact with collections via mongosh.
Purpose
Used in modern applications for schema-less data storage, rapid prototyping, and horizontal scaling.
General Syntax
Example
Demonstrates single document insertion, targeted field updating with `$set`, and conditional batch deletion with `$gt`.
Definition
MongoDB provides query operators like `$or`, `$in`, `$gt`, `$lt` for complex criteria, projections to include/exclude fields, and cursor modifiers (`sort`, `limit`).
Purpose
Enables expressive document filtering, pagination, and tailored payload retrieval.
General Syntax
Example
Performs array membership matching with `$in`, disjunction with `$or`, field projection hiding `_id`, sorting, and pagination limiting.