Introduction to Databases & SQL Basics
1. What is SQL?
SQL = Structured Query Language
It is used to store, manage, and retrieve data from relational databases.
SQL allows you to:
- Create databases
- Create tables
- Insert data
- Update and delete data
- Fetch data using queries
2. What is a Database?
A database is a collection of organised data.
Types of Databases:
1.Relational Database (RDBMS)
- Data stored in tables
- Uses SQL
- Examples: MySQL, PostgreSQL, Oracle, SQL Server 2.NoSQL Database
- Non-table structure (JSON, Key-Value, Document)
- Examples: MongoDB, Cassandra
3. What is a Table?
A table is a structure inside a database that stores data in:
- Rows → each entry (record)
- Columns → attributes (name, age, phone)
Example Table:Students
| student_id | name | age | city |
|---|---|---|---|
| 1 | Arun | 21 | Chennai |
| 2 | Priya | 22 | Coimbatore |
| 3 | Karthi | 23 | Madurai |
4. What is a Schema?
A schema is the blueprint/structure of a database.
It defines:
- Number of tables
- Columns
- Data types
- Relationships
SQL Commands
CREATE DATABASE
Used to create a new database.
CREATE DATABASE school;
USE DATABASE
Select the database to work inside.
USE school;
CREATE TABLE
Create a table with columns and data types.
CREATE TABLE students (
student_id INT,
name VARCHAR(50),
age INT,
city VARCHAR(50)
);
INSERT DATA
Insert records into the table.
INSERT INTO students (student_id, name, age, city)
VALUES (1, 'Arun', 21, 'Chennai');
Multiple insert:
INSERT INTO students VALUES
(2, 'Priya', 22, 'Coimbatore'),
(3, 'Karthi', 23, 'Madurai');
SELECT Data
Retrieve data from a table.
Fetch all columns
SELECT * FROM students;
Fetch specific columns:
SELECT name, city FROM students;
Top comments (0)