Data Manipulation Flashcards

1
Q

What is data manipulation in SQL?

A

Commands used to manipulate the actual data inside tables (CRUD operations).

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

What does CRUD stand for?

A

Create, Read, Update, Delete.

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

What is the syntax to insert records into a table?

A

INSERT INTO table_name (column1, column2, …) VALUES (value1, value2, …);

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

What happens if you don’t mention a column in the INSERT statement?

A

The column will take the NULL value by default.

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

Why should the order of values in INSERT match the order of columns?

A

Because the column/value matching is positional.

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

What does INSERT INTO allow you to do?

A

Add new records into a table.

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

Can you insert multiple records at once with INSERT INTO?

A

Yes, by separating values with commas.

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

What is the syntax to update values in a table?

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
9
Q

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

A

All records in the table will be updated.

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

Why is the WHERE clause important in an UPDATE command?

A

To target specific records and avoid unintended updates.

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

Give an example of updating an employee’s salary.

A

UPDATE employees SET salary = 60000 WHERE employee_id = 1;

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

What is the syntax to delete records from a table?

A

DELETE FROM table_name WHERE condition;

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

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

A

All records in the table will be deleted.

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

Why is the WHERE clause critical in a DELETE command?

A

To prevent accidental deletion of all data.

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

If you want to remove only employees in the ‘Sales’ department, how would you do it?

A

DELETE FROM employees WHERE department = ‘Sales’;

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

If you want to give all employees a 10% raise, what should you use?

A

UPDATE employees SET salary = salary * 1.10;

17
Q

How would you insert a new customer record with specific values?

A

INSERT INTO customers (name, email) VALUES (‘John Doe’, ‘john@example.com’);

18
Q

Spot the mistake: ‘INSERT table_name (column1, column2) VALUES (value1, value2);’

A

Correct syntax is: INSERT INTO table_name (column1, column2) VALUES (value1, value2);

19
Q

Spot the mistake: ‘UPDATE SET column1 = value1 WHERE condition;’

A

Missing table name. Correct syntax is: UPDATE table_name SET column1 = value1 WHERE condition;

20
Q

Spot the mistake: ‘DELETE table_name WHERE condition;’

A

Correct syntax is: DELETE FROM table_name WHERE condition;

21
Q

Which SQL command adds new records to a table?

A

INSERT INTO.

22
Q

Which SQL command updates existing records?

23
Q

Which SQL command removes records from a table?

24
Q

Explain why the WHERE clause is crucial in UPDATE and DELETE operations.

A

To ensure only the intended records are modified or deleted, preventing accidental changes to the whole table.

25
Q

Describe what happens if you forget to include WHERE in an UPDATE command.

A

All records in the table will be updated, which may cause data loss.

26
Q

If you accidentally run DELETE without WHERE, what is the consequence?

A

All records in the table will be deleted.

27
Q

Why is INSERT considered part of CRUD operations?

A

Because it creates new records in the database.