Databases and SELECT · מאגרי נתונים ו-SQL SELECT
Databases and tables
A database stores information in tables. A table is a grid, a bit like a spreadsheet:
- each row is one record — for example, one student;
- each column is one field — for example, the student's name or score.
This course uses a small table called student. It has 5 records and 4 fields: id, name, form, and score.
מסדי נתונים וטבלאות
מסד נתונים מאחסן מידע ב-טבלאות. טבלה היא גרף, מעט כמו טבלאון אקסל:
- כל-שורה היא רשומה אחת — לדוגמה, תלמיד אחד;
- כל-עמודה היא שדה אחד — לדוגמה, שם התלמיד או הציון שלו.
קורס זה משתמש בטבלה קטנה הנקראת student. יש לה 5 רשומות ו-4 שדות: id, name, form, וscore.
Asking for data with SELECT
To read data from a table you write a query with SELECT.
The simplest query asks for every column of every row. The star * means "all columns":
SELECTchooses the columns —*means all of them.FROM studentsays which table to read.
The database replies with a result table (also called a result set): the rows your query asked for.
בקשת נתונים באמצעות SELECT
כדי לקרוא נתונים מטבלה, כותבים בקשה עם SELECT.
הבקשה הפשוטה ביותר מבקשת כל העמודות של כל השורות. הכוכב * פירושו "כל העמודות":
SELECT * FROM student;
SELECTבוחר את העמודות —*פירושו כולן.FROM studentאומר איזו טבלה לקרוא.
מסד הנתונים מגיב עם טבלת תוצאות (נקראת גם קבוצת תוצאות): השורות שהבקשה דרשה.
A few rules
- Keywords like
SELECTandFROMare often written in capitals so they stand out. - End each statement with a semicolon
;. - An empty cell is shown as
NULL, which means "no value".
Now try it. Click Run to see the output, then Check answer.
כמה כללים
- מילות מפתח כמו
SELECTוFROMנכתבות לעיתים קרובות באותיות גדולות כדי לבלוט. - סיים כל הודעה עם נקודה-פסיק
;. - תא ריק מוצג כ
NULL, שמשמעותה "ללא ערך".
עכשיו נסה זאת. לחץ על Run כדי לראות את התוצאה, ולאחר מכן לחץ על Check answer.
Common mistakes
- End a query with a semicolon:
SELECT ... FROM table;. SELECT *returns every column — name only the ones you need.
טעויות נפוצות
- סיים שאלה בנקודה-פסיק:
SELECT ... FROM table;. SELECT *מחזיר את כל העמודות — ציין רק אלו שאתה זקוק להן.
SELECT … FROM … WHERE
WHERE keeps rows, then SELECT keeps columns — step through it. · WHERE שומר שורות, ואז SELECT שומר עמודות — עברו על כך צעד אחר צעד.
Show the whole student table — every column and every row. Use SELECT * FROM ...;. · הציגו את טבלת student השלמה — כל עמודה וכל שורה. השתמשו בSELECT * FROM ...;.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Now keep only some columns and some rows. Show just the name and score of students in form 11A. Pick the two columns and add a WHERE form = '11A'. · כעת שמרו רק חלק מהעמודות וחלק מהשורות. הצגו רק את הname והscore של תלמידים בקבוצה 11A. בחרו את שתי העמודות והוסיפו WHERE form = '11A'.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.