Summary of "Kurs MySQL odc. 1: Bazy danych. Pierwsze zapytania SELECT"
Summary of “Kurs MySQL odc. 1: Bazy danych. Pierwsze zapytania SELECT”
This first episode of the MySQL course, presented by Mirosław Zelent, introduces foundational concepts of databases and guides viewers through creating their first SQL queries using MySQL and phpMyAdmin. The lesson balances theoretical explanations with practical demonstrations to build a solid understanding of database terminology and basic SQL commands.
Main Ideas and Concepts
1. Introduction to Databases
- A database is a structured collection of data, such as user information on Facebook or records in a school library.
- Databases are organized into tables, which consist of rows (records) and columns (fields/attributes).
- Example: A school library database might have tables like “students” (with fields: first name, last name, class) and “books” (with fields: title, author, year).
- Each record (or tuple) is a single row containing values for each attribute.
- A field (or attribute) is a column storing a specific type of data (e.g., a student’s first name).
2. Keys and Relationships
- Primary Key: A unique identifier for each record in a table (e.g., Student ID, Book ID). It ensures uniqueness and data consistency.
- Foreign Key: A field in one table that refers to the primary key in another table, establishing a relationship between tables.
- Example: A “loans” table links “students” and “books” using student ID and book ID as foreign keys.
- Avoid redundancy by not repeating data unnecessarily; use keys to reference related data instead.
- Importance of planning database structure before entering data to avoid complex corrections later.
3. Database Management System (DBMS)
- DBMS is software that manages databases; MySQL is the chosen DBMS for this course.
- Other DBMS examples: PostgreSQL, Firebird, Oracle Database.
4. Using phpMyAdmin and Creating a Database
- Ensure Apache and MySQL services are running in XAMPP.
- Access phpMyAdmin via
localhost/phpmyadmin. - Create a new database (e.g., “quiz”) with UTF-8 Polish collation.
- Create tables (e.g., “questions”) with columns:
ID(primary key, integer, auto-increment)content(question text)answer_a,answer_b,answer_c,answer_d(possible answers)correct_answer(stores the correct answer as a letter)
- Add new columns (e.g., category, year) later if needed.
5. Basic MySQL Data Types
INT— integer numbersFLOAT— floating-point numbers (decimals)TEXT— strings up to 65,535 charactersLONGTEXT— very long text (billions of characters)DATE— date inYYYY-MM-DDformatTIME— time inHH:MM:SSformat
6. Inserting and Managing Data
- Auto-increment allows automatic assignment of unique IDs.
- Insert sample data into tables using phpMyAdmin.
- Export and import databases using SQL files for backup and sharing.
7. Introduction to SQL Language
- SQL (Structured Query Language) is used to manage and query databases.
- Queries can:
- Insert, update, delete data
- Retrieve data (
SELECT) - Create or modify tables
- SQL commands can be executed directly in phpMyAdmin or embedded within PHP scripts.
8. Practical SQL Queries: SELECT Statements
SELECT * FROM table_name;— select all columns from a table.SELECT column1, column2 FROM table_name;— select specific columns.WHEREclause filters records by condition, e.g.,WHERE ID=15.- Strings in conditions must be enclosed in quotes (e.g.,
'a'). - Numeric values do not require quotes.
- Logical operators:
AND— both conditions must be true.OR— at least one condition must be true.
ORDER BY column ASC|DESC— sort results ascending (default) or descending.BETWEEN value1 AND value2— select records within a range.LIKE 'pattern%'— search for values starting with a pattern (%is a wildcard).- Combining conditions with parentheses for clarity and precedence.
9. Example Queries Covered
- Select question with ID 15.
- Select questions where the correct answer is
'a'. - Select questions from the year 2007.
- Select programming questions from 2009 (using
AND). - Select content and answers from questions from 2010.
- Sort questions alphabetically by content.
- Select questions with IDs between 10 and 12.
- Select questions starting with “how”.
- Select questions containing “c+plus” in any content or answer fields (using
OR). - Select questions from categories “programming” or “operating systems and networks” from 2012.
Methodology / Step-by-Step Instructions
Creating a Database and Table in phpMyAdmin
- Open phpMyAdmin (
localhost/phpmyadmin). - Create a database with UTF-8 Polish collation.
- Create a table with appropriate columns.
- Set primary key and enable auto-increment for
ID. - Choose appropriate data types for each column.
- Save the table structure.
Inserting Data
- Use phpMyAdmin interface or SQL
INSERTstatements. - Leave auto-increment fields blank to auto-assign IDs.
Modifying Table Structure
- Add new columns via the “Structure” tab.
- Update existing records to fill new columns.
Exporting and Importing Databases
- Export database or tables to SQL files for backup.
- Import SQL files to recreate database structure and data.
Writing Basic SELECT Queries
- Use
SELECTkeyword followed by columns or*for all. - Use
FROMto specify the table. - Use
WHEREto filter records. - Use quotes for string literals.
- Combine conditions with
ANDandOR. - Use
ORDER BYto sort results. - Use
LIKEwith%wildcard for pattern matching. - Use
BETWEENfor range queries.
Testing Queries
- Save query in a
.txtfile. - Refresh browser to see query results via a custom PHP interface.
Speakers / Sources Featured
- Mirosław Zelent — primary and sole speaker, course instructor and presenter.
This episode provides a comprehensive introduction to databases, MySQL, and SQL query basics, combining theory with hands-on exercises to build confidence in managing and querying databases.
Category
Educational