Skip to content

SQL Complete Tutorial: From Zero to Expert (No Prerequisites)

What is a Database?

A database is a way to store data in a format that makes it easily accessible. Imagine having 1000 people's information in separate files and being asked to find everyone whose address contains "Civil Lines." You'd have to write a custom program in Python, which wouldn't be easy. A database solves this by organizing data so you can answer such questions instantly with simple queries.

Analogy: Database ↔ Folder, Table ↔ File, Row ↔ Data

  • A database is like a folder that contains data.
  • Inside a database, you have tables (like files in a folder).
  • Inside a table, you have rows which store the actual information.
  • Another analogy: A database is like an Excel workbook. The workbook contains multiple sheets (tables), and each sheet contains rows of data.

What is a Query?

A query is like a question you ask to a database. It's a command given to the database management system (DBMS) following a specific syntax. SQL is all about writing efficient queries that solve a problem.

DBMS: Database Management System

When we interact with a database, we don't interact directly. We interact through a DBMS (Database Management System). You give your SQL query (a command) to the DBMS, and the DBMS applies it to the database. MySQL is a very popular DBMS. Other examples include PostgreSQL and MS SQL.

Relational vs. Non-Relational Databases

Relational Databases (RDBMS)

  • Have a set schema (like an Excel table with defined columns: Name, Address, Phone, Email).
  • Data is structured in tables with rows and columns.
  • Tables can be linked using Foreign Keys.
  • Rules are strict; you must follow the schema to insert data.
  • Examples: MySQL, PostgreSQL, Oracle, MS SQL. For more depth on one major system, see A Comprehensive Guide to PostgreSQL: Basics, Features, and Advanced Concepts.

Non-Relational Databases (NoSQL)

  • Data is flexible; no set schema is followed.
  • You don't always need SQL.
  • Used when you have many read operations or want to optimize for reading.
  • Examples: MongoDB, Cassandra, Redis, Neo4j.

Installing MySQL

Windows

  1. Go to Google and search "MySQL Install."
  2. Click the first link and download the Windows MSI Installer.
  3. Choose "Full" setup, click "Next" and "Execute."
  4. After installation, set a root password and finish the setup. The MySQL Workbench will be installed.

Linux (Ubuntu)

  1. Open terminal and run sudo apt update.
  2. Run sudo apt install mysql-server.
  3. After installation, run sudo mysql_secure_installation to secure the installation.
  4. Access MySQL with sudo mysql.
  5. Create a user and grant privileges:
    CREATE USER 'harry'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON *.* TO 'harry'@'localhost';
    FLUSH PRIVILEGES;
    
  6. Install MySQL Workbench Community via the App Center. Connect using the username and password you created.

Mac

  1. Download MySQL Community Server and MySQL Workbench from the official site.
  2. Install the server (choose a root password), then install the Workbench by dragging it to Applications.
  3. Open MySQL Workbench, connect with username root and your password.

Creating Your First Database and Table

1. Create a Database

CREATE DATABASE starter_sql;
  • Click the lightning bolt icon to execute.
  • To use this database, either right-click and "Set as Default Schema" or run:
    USE starter_sql;
    

2. Create a Table

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    gender ENUM('Male', 'Female', 'Other'),
    date_of_birth DATE,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
  • Data Types: INT (integer), VARCHAR(n) (variable-length string, max n characters), ENUM(...) (choose from a list), DATE, TIMESTAMP, BOOLEAN.
  • Constraints:
    • AUTO_INCREMENT: Automatically generates a unique number (1, 2, 3...).
    • PRIMARY KEY: Uniquely identifies each row; cannot be NULL or duplicate.
    • NOT NULL: Ensures a value cannot be empty.
    • UNIQUE: Ensures all values in a column are different.
    • DEFAULT: Sets a default value if none is provided.

3. View the Table

SELECT * FROM users;
  • SELECT * selects all columns. You can also select specific columns:
    SELECT id, email FROM users;
    

CRUD Operations: The Four Pillars of Databases

CRUD stands for Create, Read, Update, Delete. These operations form the foundation of all database work, and are explored in detail in Master SQL: Comprehensive Guide to Advanced Data Analytics and Optimization.

| Operation | Action | | :--- | :--- | | Create | INSERT new records | | Read | SELECT records | | Update | UPDATE existing records | | Delete | DELETE records |

Altering and Renaming Tables

Rename a Table

RENAME TABLE users TO programmers;

Add a Column

ALTER TABLE users ADD COLUMN is_active BOOLEAN DEFAULT TRUE;

Drop a Column

ALTER TABLE users DROP COLUMN is_active;

Modify a Column's Data Type

ALTER TABLE users MODIFY COLUMN name VARCHAR(150);

Change Column Order (Example: Move email after id)

ALTER TABLE users MODIFY COLUMN email VARCHAR(100) AFTER id;

Pro Tip: Use SQL Scripts and a Handbook

  • Save your queries as .sql files (File → Save Script As). This is like writing a program in any language.
  • Download the accompanying handbook for all commands, definitions, and notes. Print it out and keep it at your workspace for quick reference. This is crucial for serious learning.

What's Next?

This tutorial sets a rock-solid foundation. From here, you'll learn to insert data, write advanced SELECT queries with WHERE, JOIN, and GROUP BY, understand Foreign Keys, and explore AI-assisted SQL. To build on what you've learned, check out Comprehensive SQL Course: From Basics to Advanced Database Design for a structured path covering everything from fundamentals to complex queries. For targeted interview preparation, see Complete SQL Interview Prep: 15 Must-Know Queries & Concepts. Enroll in the complete Data Science course linked in the description to become a job-ready data scientist.

Keep this summary

Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.

Save to LunaNotes

Or summarise for another video.

32K+ people have turned 65K+ videos into notes

“Very useful tool. I'm using it for the last couple weeks and I'm loving it so far. Makes learning on YouTube a great experience.”
Bhai Chrome Web Store review

This summary and transcript were automatically generated using AI with the Free YouTube transcript summary tool by LunaNotes.

Related summaries

Comprehensive SQL Course: From Basics to Advanced Database Design

Comprehensive SQL Course: From Basics to Advanced Database Design

Master SQL with this full beginner-friendly course covering database fundamentals, MySQL installation, table creation, data manipulation, complex querying, joins, triggers, ER diagrams, and converting ER diagrams to schemas. Learn practical examples and advanced techniques to design and manage relational databases effectively.

Complete SQL Interview Prep: 15 Must-Know Queries & Concepts

Complete SQL Interview Prep: 15 Must-Know Queries & Concepts

Master essential SQL interview questions in this comprehensive guide covering 15+ crucial topics, including joins, window functions, aggregations, and data manipulation. Learn to solve common challenges like finding second highest salaries, removing duplicates, and handling NULL values with clear, step-by-step query explanations.

A Comprehensive Guide to PostgreSQL: Basics, Features, and Advanced Concepts

A Comprehensive Guide to PostgreSQL: Basics, Features, and Advanced Concepts

Learn PostgreSQL fundamentals, features, and advanced techniques to enhance your database management skills.

Master SQL: Comprehensive Guide to Advanced Data Analytics and Optimization

Master SQL: Comprehensive Guide to Advanced Data Analytics and Optimization

Explore an extensive SQL course covering fundamentals to advanced topics including data warehousing, analytics, complex querying, performance tuning, and AI-powered coding assistance. Learn practical techniques, real-world project workflows, and best practices to excel in data engineering and analysis using SQL.

Introduction to Database Management Systems: Basics and Key Concepts

Introduction to Database Management Systems: Basics and Key Concepts

This video provides a foundational overview of Database Management Systems (DBMS), covering essential definitions, functionalities, and properties. Using a university database example, it explains how DBMS manages, manipulates, and shares data efficiently to meet specific organizational needs.

Found this summary useful?

Take it with you. One click puts it in your own LunaNotes library.

Save to LunaNotes

Start taking better notes today with LunaNotes