Challenge your understanding of essential SQL querying concepts and foundational database design principles. This beginner-friendly quiz covers common SQL commands, table structure, data types, keys, and relational database basics to help you solidify your skills in database management.
Which SQL statement would retrieve all columns from a table named 'employees'?
Explanation: The correct way to select all columns from the 'employees' table is 'SELECT * FROM employees;'. The asterisk (*) acts as a wildcard for all columns. 'GET ALL employees;' is not valid SQL syntax. 'SELECT columns FROM employees;' is incorrect because 'columns' is not a keyword. 'FETCH employees ALL;' is also not valid SQL; the FETCH command works differently.
What is the primary purpose of a primary key in a relational database table?
Explanation: A primary key uniquely identifies each row in a table, ensuring no duplicate records exist. While primary keys may help with retrieval speed via indexing, their main function is enforcing uniqueness. They do not encrypt data or count rows; those are different database functionalities.
Which data type would you use to store dates in a SQL table?
Explanation: The 'DATE' data type is designed for storing calendar dates in SQL. 'VARCHAR' is meant for variable-length character strings, 'INTEGER' for whole numbers, and 'DECIMAL' for fixed-point numeric values, making them unsuitable for date storage.
Which SQL command is used to add a new record to the 'products' table?
Explanation: 'INSERT INTO products VALUES (...);' is the correct syntax for adding a new record. 'ADD ROW' and 'CREATE ROW' are not SQL commands. 'UPDATE' is used to modify existing rows, not to add new ones.
In a student-enrollment database, what is the purpose of a foreign key in the 'enrollments' table referencing the 'students' table?
Explanation: A foreign key in 'enrollments' points to the 'students' table, creating a relational link and ensuring referential integrity. It does not directly improve server speed, delete data automatically (unless specified with cascade rules), or store sensitive information like passwords.
Which part of a SQL query filters rows based on a specified condition?
Explanation: The 'WHERE' clause filters results to include only rows that meet a specific condition. 'GROUP BY' groups rows for aggregation, 'ORDER BY' sorts the results, and 'ALTER' is used for modifying table structures, not for filtering data.
What is the main goal of table normalization in database design?
Explanation: Normalization is a design process used to reduce redundant data and ensure logical data dependencies. It does not affect network connection speed or visual aspects such as font size. Removing all indexes is not related and could even harm performance.
In SQL, what does the value NULL represent in a table cell?
Explanation: NULL indicates that a value is missing or not applicable, representing an absence of any value. It is not a zero (numerical value) nor the text 'NULL'. The default value for the column may be different and is set by the column's schema.
Which SQL function would you use to calculate the total number of rows in a table?
Explanation: 'COUNT()' returns the total number of rows that match a query. 'SUM()' adds up numerical values in a column, 'AVG()' computes averages, and 'MAX()' returns the highest value, none of which are meant for simply counting rows.
What does the UNIQUE constraint ensure when applied to a column in a table?
Explanation: A UNIQUE constraint prevents duplicate values in a column, ensuring all entries are distinct in that field. It does not enforce default values, restrict data types to numbers only, or control row ordering, which are separate concerns.