Unit 3 Database - Implementation - SQL DELETE Flashcards

1
Q

What is the purpose of the DELETE keyword in SQL?

A

The DELETE keyword is used to delete rows in a table.

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

What is the basic syntax for a DELETE statement?

A

DELETE FROM table_name 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 a DELETE statement?

A

The WHERE clause specifies which rows to delete. Without it, all rows in the table will be deleted.

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

Example: How would you delete a user with userid = 7914?

A

DELETE FROM user WHERE userid = 7914;

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

How do you delete rows based on text values?

A

Use the DELETE statement with a WHERE clause that matches text values.

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

Example: Delete all hairdressers working at ‘West Style’ salon.

A

DELETE FROM hairdresser WHERE salon = ‘West Style’;

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

How do you delete rows based on numeric values?

A

Use the DELETE statement with a WHERE clause that matches numeric conditions.

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

Example: Delete all clients with hairdresserid = 2210.

A

DELETE FROM client WHERE hairdresserid = 2210;

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

What are cascade deletes in SQL?

A

Cascade deletes automatically delete related foreign key rows when a primary key row is deleted.

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

What happens if your RDBMS does not support cascade deletes?

A

You must manually delete related foreign key rows using additional DELETE statements.

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

Example: Delete a hairdresser with hairdresserid = 3030 and its related clients.

A

DELETE FROM hairdresser WHERE hairdresserid = 3030; DELETE FROM client WHERE hairdresserid = 3030;

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

How do you delete rows based on multiple conditions using AND?

A

Use the AND operator in the WHERE clause to specify multiple conditions.

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

Example: Delete all clients with clientid between 15000 and 17500.

A

DELETE FROM client WHERE clientid > 15000 AND clientid < 17500;

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

How do you delete rows based on multiple conditions using OR?

A

Use the OR operator in the WHERE clause to specify multiple conditions.

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

Example: Delete clients with clientid = 32100 or clientid = 40292.

A

DELETE FROM client WHERE clientid = 32100 OR clientid = 40292;

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

What precaution should you take before running a DELETE statement?

A

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

17
Q

What happens if you omit the WHERE clause in a DELETE statement?

A

All rows in the table will be deleted.

18
Q

How can you check if rows were successfully deleted?

A

Use an appropriate SELECT query to confirm that the data has been removed.