What is a database?#
A database is an organised collection of data that can be stored, searched and updated efficiently. Your bank account, a railway reservation, an Instagram post and your college marksheet all live in databases.
A DBMS (Database Management System) is the software that manages the database: it stores the data, answers queries, keeps data consistent and controls who can access what. Examples: MySQL, PostgreSQL, Oracle, Microsoft SQL Server, SQLite.
Most business data lives in relational databases (RDBMS), where data is kept in tables that are related to each other.
Database = व्यवस्थित तरीके से रखा गया data (जैसे college का पूरा record)। DBMS वो software है जो इस data को संभालता है - MySQL, Oracle, PostgreSQL आदि। Relational database में data tables में रहता है - हर table एक चीज़ के बारे में (students, courses), हर row एक record और हर column एक जानकारी (नाम, शहर, CGPA)।
Tables, rows and columns#
| student_id | name | city | dept_id | cgpa |
|---|---|---|---|---|
| 101 | Aarav Gupta | Bhopal | 1 | 7.06 |
| 102 | Diya Soni | Indore | 1 | 7.18 |
| 104 | Sneha Gupta | Indore | 2 | 7.52 |
- A table (relation) stores one type of entity - here, students.
- A row (record, tuple) is one student.
- A column (field, attribute) is one property, with a fixed data type (number, text, date).
Keys#
- Primary key (PK) - uniquely identifies each row; cannot be NULL or duplicated.
student_idinstudents. - Foreign key (FK) - a column that refers to the primary key of another table, creating a relationship.
students.dept_id→departments.dept_id. - Candidate key - any column that could be the primary key (for example
email, if unique). - Composite key - a primary key made of several columns together.
The college database used in this course#
Every query in this course runs on a practice database called college:
departments (dept_id PK, name, building, founded)
▲ 1 ▲ 1
│ │
│ many │ many
students (student_id PK, name, gender, city, dept_id FK, year, cgpa, email, admission_date, fee)
▲ 1
│ many
enrollments (enroll_id PK, student_id FK, course_id FK, marks, grade)
│ many
▼ 1
courses (course_id PK, title, dept_id FK, credits, semester)
faculty (faculty_id PK, name, dept_id FK, designation, salary, joining_date, reports_to FK → faculty)
It has 6 departments, 30 students, 13 courses, 11 faculty members and 65 enrollments. Run your first query:
SELECT * means "all columns", and FROM students names the table. The result is itself a table.
When a try-it contains several queries, each result table is shown in turn.
What is SQL?#
SQL (Structured Query Language, pronounced "S-Q-L" or "sequel") is the standard language for working with relational databases. You describe what you want; the database works out how to get it.
| Category | Purpose | Commands |
|---|---|---|
| DQL - Data Query Language | read data | SELECT |
| DDL - Data Definition Language | define structure | CREATE, ALTER, DROP, TRUNCATE |
| DML - Data Manipulation Language | change data | INSERT, UPDATE, DELETE |
| DCL - Data Control Language | permissions | GRANT, REVOKE |
| TCL - Transaction Control Language | transactions | BEGIN, COMMIT, ROLLBACK, SAVEPOINT |
SQL syntax basics#
- Statements end with a semicolon
;. - Keywords are not case-sensitive (
SELECT=select), but writing them in CAPITALS is the convention. - Text values go in single quotes:
'Indore'. - Comments:
-- single lineand/* multi-line */. - Extra spaces and new lines are ignored, so format queries for readability.
This course runs on SQLite, a small database engine that runs in your browser. The SQL you learn is standard and works in MySQL, PostgreSQL and SQL Server too; where a function differs (like LIMIT vs TOP, or date functions), the lesson points it out.
Summary#
- A relational database stores data in related tables of rows and columns; a DBMS manages it.
- Primary keys identify rows; foreign keys link tables.
- SQL has five command families: DQL, DDL, DML, DCL, TCL.
SELECT * FROM table;shows a whole table.