1. DBMS Basics

Database: Organized collection of data.
RDBMS: Relational Database (Data stored in tables). Example: MySQL.
Keys:
- Primary Key: Unique identifier for a record.
- Candidate Key: Keys jo Primary Key ban sakti hain.
- Foreign Key: Used to link two tables.

2. SQL Commands

SQL (Structured Query Language) database se baat karne ki language hai.

-- Create Table
CREATE TABLE Student (
    RollNo INT PRIMARY KEY,
    Name VARCHAR(50),
    Marks INT
);

-- Insert Data
INSERT INTO Student VALUES (1, 'Amit', 95);

-- Select Data (Query)
SELECT * FROM Student WHERE Marks > 90;

3. Python-SQL Connectivity

Python ko database se connect karne ke liye `mysql.connector` library use hoti hai.

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="1234",
  database="school"
)

cursor = mydb.cursor()
cursor.execute("SELECT * FROM Student")
for x in cursor:
  print(x)
Google Ad Here

Quiz Time!

Q1. Which command is used to fetch data?

(a) FETCH (b) GET (c) SELECT (d) EXTRACT

Q2. Which key cannot have NULL values?

(a) Foreign Key (b) Primary Key (c) Alternate Key (d) Candidate Key