DBMS Review

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

COUNT(*)

Counts all rows, including rows with NULL values.

2
New cards

COUNT(column_name)

Counts only rows where the column is NOT NULL.

3
New cards

COUNT(DISTINCT column)

Counts unique non-null values in a column.

4
New cards

SUM(column)

Adds all numeric values in a column; ignores NULL.

5
New cards

AVG(column)

Calculates average of non-null values.

6
New cards

MIN(column)

Returns the smallest non-null value.

7
New cards

MAX(column)

Returns the largest non-null value.

8
New cards

SUM(isActive) (boolean column)

Counts TRUE values because TRUE=1, FALSE=0.

9
New cards

COUNT(isActive) (boolean column)

Counts TRUE + FALSE values but excludes NULL.

10
New cards

How to count only active users (TRUE)

SELECT COUNT(*) FROM Users WHERE isActive = TRUE;

11
New cards

How to count only inactive users (FALSE)

SELECT COUNT(*) FROM Users WHERE isActive = FALSE;

12
New cards

What does AS active_count do?

Creates an alias and renames the output column to "active_count".

13
New cards

What is an alias in SQL?

A temporary name given to a column or table using AS.

14
New cards

What does DISTINCT do in SQL?

Returns unique values from a column.

15
New cards

What does GROUP BY do?

Groups rows by shared values so aggregates can be applied.

16
New cards

What does HAVING do?

Filters groups after aggregation.

17
New cards

What does WHERE do?

Filters rows before grouping or aggregation.

18
New cards

Primary Key (PK)

A unique identifier for each row; cannot be NULL.

19
New cards

Foreign Key (FK)

A column that references a primary key in another table.

20
New cards

Candidate Key

A field or combination of fields that can uniquely identify a row.

21
New cards

Composite Key

A key made of two or more columns.

22
New cards

1NF Definition

No repeating groups; all values are atomic.

23
New cards

2NF Definition

In 1NF and no partial dependencies.

24
New cards

3NF Definition

In 2NF and no transitive dependencies.

25
New cards

BCNF Definition

Every determinant must be a candidate key.

26
New cards

Partial Dependency

A non-key attribute depends on only part of a composite key.

27
New cards

Transitive Dependency

A non-key attribute depends on another non-key attribute.

28
New cards

INNER JOIN meaning

Returns rows with matching values in both tables.

29
New cards

LEFT JOIN meaning

Returns all rows from the left table and matching rows from the right.

30
New cards

RIGHT JOIN meaning

Returns all rows from the right table and matching rows from the left.

31
New cards

FULL OUTER JOIN meaning

Returns all rows from both tables, matched or unmatched.

32
New cards

JOIN scenario: Employees with Managers

SELECT e.name, m.name FROM Employees e LEFT JOIN Employees m ON e.managerid = m.empid;

33
New cards

JOIN scenario: List customers who placed orders

SELECT c.name, o.orderid FROM Customers c JOIN Orders o ON c.customerid = o.customer_id;

34
New cards

JOIN scenario: Students with their Courses

SELECT s.name, c.coursename FROM Students s JOIN Enrollments e ON s.id = e.studentid JOIN Courses c ON e.course_id = c.id;

35
New cards

JOIN scenario: Departments with avg salary

SELECT d.name, AVG(e.salary) FROM Departments d JOIN Employees e ON e.deptid = d.deptid GROUP BY d.name;

36
New cards

JOIN scenario: Products with No Orders

SELECT p.productname FROM Products p LEFT JOIN Orders o ON p.id = o.productid WHERE o.product_id IS NULL;

37
New cards

Subquery: Employees earning above department average

SELECT e.name, e.salary FROM Employees e JOIN (SELECT deptid, AVG(salary) AS avgsalary FROM Employees GROUP BY deptid) x ON e.deptid = x.deptid WHERE e.salary > x.avgsalary;

38
New cards

Query: Customers with more than 5 orders

SELECT customerid FROM Orders GROUP BY customerid HAVING COUNT(*) > 5;

39
New cards

Window function: Top 3 salaries per department

SELECT name, deptid, salary FROM (SELECT name, deptid, salary, ROWNUMBER() OVER (PARTITION BY deptid ORDER BY salary DESC) AS rn FROM Employees) x WHERE rn <= 3;

Explore top flashcards