إعلانيمكن أن تكون علامتك التجارية هناعلامتك التجارية هنافي كل صفحة من Darslab · طلاب وأولياء أمور ومعلمونinfo@darslab.comاسأل عن الأسعارالأسعارinfo@darslab.com
☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

The database program, the Terms table and SQL

الأسبوع 7 · الوحدة ٢ «متطلبات ومراحل إنتاج المشروع» (٤) مرحلة إنشاء جداول قاعدة البيانات (٣): برنامج قاعدة البيانات، الجداول والاستعلامات، جدول المصطلحات في القاموس، أوامر SQL الأربعة · 3 دروس
3

Four commands: INSERT, SELECT, UPDATE, DELETE

ICT Secondary 2 Term 1, Unit 2, Topic 2: pp. 53–55
GoalTrace the four SQL commands INSERT, SELECT, UPDATE and DELETE on a small table, before and after.
New words
INSERT · adds a new record to a tableSELECT · shows records, all or only those that meet a condition (WHERE)UPDATE · changes values in existing recordsDELETE · removes records from a table
Explanation

SQL has four commands for records. INSERT adds a record: you name the table, the fields and the values in the same order. SELECT shows records, and WHERE limits them. UPDATE changes values: SET says what to change and WHERE says which records. DELETE removes records, and WHERE says which. SQL words are not case-sensitive, but capitals make a command easier to read. Strings go in single quotes. Now the most important warning: UPDATE and DELETE without WHERE act on every row. DELETE FROM Terms; with no condition empties the whole table. Always write the WHERE first and check it. In the INSERT below we give the id ourselves; if you leave it out, the database must be set to count the id up by itself, otherwise the command fails.

CommandJobWHERE?
INSERTadds a recordnot used
SELECTshows recordslimits what is shown
UPDATEchanges recordswithout it, every row changes
DELETEremoves recordswithout it, every row goes
Worked examples
Sql
1INSERT INTO Terms (id, Term, Trans, Defe, Picture)
2VALUES (4, 'keyboard', 'لوحة مفاتيح', 'Keys for typing letters and numbers.', 'pic/keyboard.webp');
Output
1 row affected
Start from the table with three records (ids 1, 2, 3). INSERT adds a fourth record. The table now has four rows, and the new one is id 4, keyboard.
Sql
1SELECT id, Term FROM Terms WHERE id = 2;
Output
id | Term
2 | cable
SELECT with WHERE shows only the matching record, and the table is not changed.
idTermTransDefePicture
1routerموجهPasses data between networks.pic/router.webp
2cableكابلA wire that carries signals or power.pic/cable.webp
4keyboardلوحة مفاتيحKeys for typing letters and numbers.pic/keyboard.webp
Continue with the four-row table (ids 1, 2, 3, 4). UPDATE changes the definition of record 2 only. Then DELETE removes record 3. The table after both commands has the rows 1, 2 (with the new definition) and 4. Command 1: UPDATE Terms SET Defe = 'A wire that carries signals or power.' WHERE id = 2; Command 2: DELETE FROM Terms WHERE id = 3;
Sql
1UPDATE Terms SET Picture = 'pic/none.webp';
Output
3 rows affected
The danger. Here UPDATE has no WHERE, so every row gets the same picture path. Always check for WHERE before you run an UPDATE or a DELETE.
Class activity

On paper, copy the Terms table with three records. Write the commands for: adding a term of your own, correcting one definition, and removing one term. After each command draw the table again. Then write the same UPDATE without WHERE and explain what would happen.

Practice
1
Which command adds a record and which one removes one?
2
What does WHERE do in SELECT, UPDATE and DELETE?
3
What happens if you run DELETE FROM Terms; without WHERE?
4
Why does the lesson’s INSERT give id 4 itself?