Unit 3 Database - Implementation - SQL UPDATE Flashcards

1
Q

What is the purpose of the UPDATE query?

A

The UPDATE query is used to amend rows in a table and can update multiple rows at the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the basic syntax of an UPDATE query?

A

UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is the WHERE clause important in an UPDATE query?

A

The WHERE clause specifies which rows to update; without it, all rows in the table will be updated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Example: How would you update a user’s last login date to ‘01/01/2019’ where userid is 7914?

A

UPDATE user SET lastlogin = ‘01/01/2019’ WHERE userid = 7914;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you update one row value in a table?

A

Use the UPDATE query with a specific WHERE condition to target one row.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Example: Update the salon to ‘Westside’ for hairdresserid 2210.

A

UPDATE hairdresser SET salon = ‘Westside’ WHERE hairdresserid = 2210;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you update several row values at once?

A

Use the UPDATE query with a condition that matches multiple rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Example: Change hairdresserid to 3030 where it equals 1928.

A

UPDATE client SET hairdresserid = 3030 WHERE hairdresserid = 1928;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an equi-join used for in an UPDATE query?

A

An equi-join updates rows based on matching values between two tables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Example: Update client.hairdresserid to 3030 where it matches hairdresser.hairdresserid and equals 1928.

A

UPDATE client, hairdresser SET client.hairdresserid = 3030 WHERE client.hairdresserid = hairdresser.hairdresserid AND hairdresser.hairdresserid = 1928;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What should you do when updating a primary key?

A

Ensure corresponding foreign key values are updated to maintain referential integrity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Example: Update hairdresserid to 9255 where userId is 2210.

A

UPDATE hairdresser SET hairdresserid = 9255 WHERE userId = 2210;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens if your RDBMS does not support cascade updates?

A

You must manually update corresponding foreign keys using another UPDATE query.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Example: Manually update foreign keys for client table after changing a primary key.

A

UPDATE client SET hairdresserid = 9255 WHERE hairdresserid = 2210;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can you update text columns based on other text values?

A

Use the UPDATE query with a condition matching text values in the WHERE clause.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Example: Update lastname to ‘McLeod’ where salon is ‘On The Corner’.

A

UPDATE hairdresser SET lastname = ‘McLeod’ WHERE salon = ‘On The Corner’;

17
Q

How can you update number columns based on other numbers?

A

Use the UPDATE query with numeric conditions in the WHERE clause.

18
Q

Example: Change hairdresserid to 3030 where it equals 2019.

A

UPDATE client SET hairdresserid = 3030 WHERE hairdresserid = 2019;

19
Q

How can you update text columns based on numbers?

A

Use the UPDATE query with numeric conditions in the WHERE clause.

20
Q

Example: Update clientfirstname to ‘George’ where clientid equals 11766.

A

UPDATE client SET clientfirstname = ‘George’ WHERE clientid = 11766;

21
Q

What precaution should you take before running an UPDATE query?

A

Run a SELECT query with the same WHERE clause to verify which records will be updated.

22
Q

What happens if you omit the WHERE clause in an UPDATE query?

A

All rows in the table will be updated, which can lead to unintended changes.