0% found this document useful (0 votes)
7 views6 pages

SQL Imp

The document provides an overview of databases and Database Management Systems (DBMS), explaining their purpose and the types of SQL commands, including DDL, DML, DQL, DCL, and TCL. It details various SQL functionalities such as SELECT, WHERE, JOINs, and aggregate functions, along with their usage and differences. Additionally, it discusses scenarios for using specific SQL commands and the logical execution order of SQL statements.

Uploaded by

Decent Ladaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

SQL Imp

The document provides an overview of databases and Database Management Systems (DBMS), explaining their purpose and the types of SQL commands, including DDL, DML, DQL, DCL, and TCL. It details various SQL functionalities such as SELECT, WHERE, JOINs, and aggregate functions, along with their usage and differences. Additionally, it discusses scenarios for using specific SQL commands and the logical execution order of SQL statements.

Uploaded by

Decent Ladaka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What is a Database?

A database is an organized collection of data stored electronically and managed using a


DBMS.

2. What is a DBMS?
A Database Management System is software used to create, store, retrieve, and manage
data in databases.

3. Why do we use databases?


To store data securely, avoid redundancy, and retrieve data efficiently.

4. What are the types of SQL commands?


DDL – Data Definition Language
DML – Data Manipulation Language
DQL – Data Query Language
DCL – Data Control Language
TCL – Transaction Control Language

5. What is DDL?
DDL commands define or modify database structure.
Examples: CREATE, ALTER, DROP, TRUNCATE

6. What is DML?
DML commands manipulate data in tables.
Examples: INSERT, UPDATE, DELETE

7. What is DQL?
DQL is used to fetch data from tables.
Example: SELECT

8. What is DCL?
DCL controls access to data.
Examples: GRANT, REVOKE

9. What is TCL?
TCL manages transactions.
Examples: COMMIT, ROLLBACK, SAVEPOINT
10. What is SELECT?
SELECT is used to retrieve data from a table.

11. What is FROM?


FROM specifies the table from which data is fetched.

12. What is WHERE?


WHERE filters rows based on conditions.

13. Can we use SELECT without FROM?


Yes, for calculations or constants.

14. Can WHERE be used without SELECT?


No.

15. Difference between SELECT * and SELECT column_name?


SELECT * retrieves all columns
SELECT column_name retrieves specific columns

16. What is AND operator?


Returns records when all conditions are true.

17. What is OR operator?


Returns records when any condition is true.

18. What is NOT operator?


Negates the condition.

19. Can AND & OR be used together?


Yes, using parentheses.

20. Which has higher priority: AND or OR?


AND has higher priority.

21. What is ORDER BY?


Used to sort result set.

22. Default sorting order?


Ascending (ASC).

23. How to sort in descending order?


Using DESC.

24. Can ORDER BY sort multiple columns?


Yes.

25. Can ORDER BY be used with WHERE?


Yes.

26. Is ORDER BY DQL or DML?


DQL.

27. What are wildcards?


Special characters used to match patterns.

28. What is LIKE?


Used with wildcards to search patterns.

29. What does % wildcard mean?


Matches zero or more characters.

30. What does _ wildcard mean?


Matches exactly one character.

31. Give a real-time example of LIKE.


Finding names starting with ‘A’.

32. Can LIKE be used with WHERE?


Yes.

33. What are aggregate functions?


Functions that return a single value from multiple rows.

34. What does COUNT() do?


Returns number of rows.
35. Difference between COUNT(*) and COUNT(column)?
COUNT(*) counts all rows
COUNT(column) ignores NULLs

36. What does SUM() do?


Adds numeric values.

37. What does AVG() do?


Returns average value.

38. What does MIN() do?


Returns lowest value.

39. What does MAX() do?


Returns highest value.

40. Do aggregate functions ignore NULL?


Yes.

41. What is GROUP BY?


Groups rows for aggregation.

42. Why is GROUP BY used?


To summarize data.

43. Can GROUP BY be used without aggregate?


Yes.

44. What is HAVING?


Filters grouped results.

45. Difference between WHERE and HAVING?


WHERE filters rows
HAVING filters groups

46. Can HAVING be used without GROUP BY?


Yes.
47. Which executes first: WHERE or HAVING?
WHERE.

48. Can aggregate functions be used in WHERE?


No.

49. What is a JOIN?


Used to combine data from multiple tables.

50. What is INNER JOIN?


Returns only matching records from both tables.
51. What is LEFT JOIN?
Returns all rows from left table and matched rows from right table.
52. What is RIGHT JOIN?
Returns all rows from right table and matched rows from left table.

53. Difference between INNER JOIN and LEFT JOIN?


INNER returns common records, LEFT returns all left records.

54. Which JOIN returns unmatched rows?


LEFT, RIGHT joins.

55. What happens if join condition is missing?


Creates Cartesian product.

56. Can we join more than two tables?


Yes.

57. Can joins be used with WHERE?


Yes.

58. Which join is most used in real projects?


INNER JOIN.

59. What is equi join?


Join using equal condition.

60. What is non-equi join?


Join using non-equal conditions.

61. What is SQL logical execution order?


FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY

62. Why is execution order important?


To understand filtering and aggregation behavior.

SCENARIO-BASED QUESTIONS
63. When would you use HAVING instead of WHERE?
When filtering aggregated data.

64. When would you use ORDER BY?


When sorted output is required.

65. When would you use LIKE instead of = ?


For pattern matching.

66. When would you use LEFT JOIN?


When all records from left table are required.

67. Why are joins better than subqueries?


Better performance and readability.

68. Can SELECT be used without WHERE?


Yes.

69. Is WHERE mandatory?


No.

70. Is GROUP BY mandatory for aggregate?


No, but required with non-aggregated columns.

You might also like