Card 5: Introduction to SQL

Once you have a database, how do you talk to it? You use a special language called SQL (Structured Query Language). Think of it as the language of databases.

1. SELECT: Asking for Data

Story: The `SELECT` command is used to retrieve data from a database. It's like asking a question.

Analogy: You ask the village registrar, "Can you SELECT all the farmers from 'Guntur' district?"

Code: `SELECT * FROM Farmers WHERE district = 'Guntur';`

2. INSERT: Adding New Data

Story: The `INSERT` command adds a new row of data into a table.

Analogy: A new family moves into the village. You INSERT their details into the village records.

Code: `INSERT INTO Farmers (name, village) VALUES ('Krishna', 'Mangalagiri');`

3. UPDATE: Changing Existing Data

Story: The `UPDATE` command modifies existing data in a table.

Analogy: Someone changes their phone number. You find their name and UPDATE their record with the new number.

Code: `UPDATE Farmers SET phone_number = '9999988888' WHERE name = 'Krishna';`

4. DELETE: Removing Data

Story: The `DELETE` command removes one or more rows from a table.

Analogy: A family moves out of the village. You find their record and DELETE it from the registry.

Code: `DELETE FROM Farmers WHERE name = 'Krishna';`

Key Technical Terms

Knowledge Check

You want to add a new book to your library database. Which SQL command would you use?