notes Flashcards

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

What is the goal of the lecture on SQL and Boolean Logic?

A

Understand Boolean Logic and SQL Querying, learn how logic gates, truth tables, and Venn diagrams apply to database queries, master SQL commands for data manipulation, querying, and management, and build a structured approach to writing SQL queries efficiently.

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

Who developed Boolean Logic?

A

George Boole (1815-1864) developed Boolean Logic.

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

What are the basic values in Boolean Logic?

A

True (1) and False (0).

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

What are the logical operators in Boolean Logic?

A

AND, OR, NOT.

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

What is a truth table?

A

A truth table helps evaluate logical expressions.

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

What does the AND operator do in SQL?

A

Both conditions must be true.

Example: SELECT * FROM employees WHERE department = ‘HR’ AND salary > 50000;

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

What does the OR operator do in SQL?

A

At least one condition must be true.

Example: SELECT * FROM employees WHERE department = ‘HR’ OR department = ‘IT’;

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

What does the NOT operator do in SQL?

A

Negates a condition.

Example: SELECT * FROM employees WHERE NOT department = ‘HR’;

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

How do Venn diagrams relate to SQL queries?

A

They represent intersection (AND, INNER JOIN), union (OR, UNION), and difference (NOT, MINUS).

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

What is SQL used for?

A

Defining database structures (DDL), manipulating data (DML), querying data (DQL), and controlling access (DCL).

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

What is the purpose of the SELECT statement in SQL?

A

The SELECT command retrieves data.

Example: SELECT first_name, last_name FROM employees;

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

How do you filter data in SQL?

A

Using the WHERE clause.

Example: SELECT * FROM employees WHERE salary > 60000;

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

How do you sort data in SQL?

A

Using the ORDER BY clause.

Example: SELECT * FROM employees ORDER BY salary DESC;

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

How do you remove duplicates in SQL?

A

Using the DISTINCT keyword.

Example: SELECT DISTINCT department FROM employees;

17
Q

What is an INNER JOIN in SQL?

A

Returns matching records.

Example: SELECT orders.order_id, customers.customer_name FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id;

18
Q

What is a LEFT JOIN in SQL?

A

Returns all from the left, matching from the right.

Example: SELECT customers.customer_name, orders.order_id FROM customers LEFT JOIN orders ON customers.customer_id = orders.customer_id;

19
Q

What is the COUNT() function in SQL?

A

Counts rows.

Example: COUNT(*)

20
Q

What is the SUM() function in SQL?

A

Adds values.

Example: SUM(salary)

21
Q

What is the AVG() function in SQL?

A

Calculates average.

Example: AVG(salary)

22
Q

What is the purpose of the INSERT statement?

A

Inserts data into a table.

Example: INSERT INTO employees (first_name, last_name, salary) VALUES (‘John’, ‘Doe’, 60000);

23
Q

How do you update data in SQL?

A

Using the UPDATE statement.

Example: UPDATE employees SET salary = 70000 WHERE first_name = ‘John’;

24
Q

How do you delete data in SQL?

A

Using the DELETE statement.

Example: DELETE FROM employees WHERE department = ‘HR’;

25
How do you create a table in SQL?
Using the CREATE TABLE statement. ## Footnote Example: CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(50) NOT NULL, salary INT);
26
How do you alter a table in SQL?
Using the ALTER TABLE statement. ## Footnote Example: ALTER TABLE employees ADD COLUMN age INT;
27
How do you drop a table in SQL?
Using the DROP TABLE statement. ## Footnote Example: DROP TABLE employees;
28
What is the purpose of creating an index in SQL?
Improves search speed. ## Footnote Example: CREATE INDEX idx_salary ON employees (salary);
29
What is a view in SQL?
A virtual table based on the result set of a SELECT statement. ## Footnote Example: CREATE VIEW high_salary AS SELECT * FROM employees WHERE salary > 80000;
30
What is a trigger in SQL?
A set of instructions that are executed in response to certain events on a table. ## Footnote Example: CREATE TRIGGER before_insert BEFORE INSERT ON employees FOR EACH ROW SET NEW.salary = 50000 WHERE NEW.salary IS NULL;