SQL beginner course · Chapter 1 of 10
SQL Foundations: Syntax, Relational Tables and Codd’s Rules explained in simple steps. Examples use practice tables such as students and scores; adapt names to your database.
SQL syntax
A SQL statement is an instruction to the database. SELECT chooses columns, FROM names the table, and WHERE filters rows. Keywords are often written in capitals for reading; names and string values still matter.
Example
SELECT student_name FROM students WHERE active = 1;Expected result: Only active student names appear.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
How a table works
A row represents one item, a column describes one property, and a primary key identifies the row. A relational design connects tables through keys instead of repeating every detail.
Example
SELECT student_id, student_name FROM students;Expected result: Each result row has one student identifier and name.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Codd’s relational rules
The relational model treats information as values in tables. Codd’s rules describe qualities of a relational database, including access through the table model and logical independence. They are design principles, not SQL commands.
Example
SELECT student_name FROM students WHERE student_id = 7;Expected result: The key identifies one logical row.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
SQL standards and dialects
SQL is standardized, but vendors add features and different syntax. The common SELECT, WHERE and JOIN ideas transfer well. Check your database manual for CREATE DATABASE, LIMIT, TOP and procedures.
Example
SELECT DISTINCT department FROM students;Expected result: The shared idea is one row per distinct department.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
SQL history and statement parts
SQL grew from the relational model proposed by E. F. Codd. In a query, SELECT is a clause, grade >= 8 is a predicate, and grade + 1 is an expression. SQL has standard revisions, but implementations vary.
Example
SELECT student_name, grade + 1 AS next_grade FROM students WHERE grade >= 8;Expected result: Each matching row shows a calculated grade.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Quick review
Explain each concept in your own words. Recreate one example without looking at the code. Compare your result with the expected result above.
Browse the full SQL learning path. This is original teaching material; the syllabus was checked against the w3resource SQL tutorial index.
No comments:
Post a Comment
Please do not enter any spam link in the comment box.