Explore essential SQL concepts and database design best practices with this quiz, covering key topics such as relational tables, normalization, query syntax, and data integrity. Ideal for learners seeking a solid foundation in working with databases and understanding basic SQL operations.
In a table storing employee information, which column is the best candidate for a primary key?
Explanation: EmployeeID is the best candidate for a primary key because it provides a unique identifier for each record. FirstName may not be unique as multiple employees can share the same first name. Department groups employees and is not unique across individuals. Salary can repeat for different employees, making it unsuitable as a primary key.
Which SQL statement is used to retrieve data from a table named 'Customers'?
Explanation: The 'SELECT * FROM Customers;' statement is the standard SQL command for retrieving data from the Customers table. 'REMOVE FROM Customers;' is not a valid SQL statement. 'GET ALL Customers;' and 'PULL DATA FROM Customers;' are not recognized SQL commands, even though they sound descriptive.
What is the primary purpose of a foreign key in relational database design?
Explanation: A foreign key is used to create a relationship between two tables by referencing the primary key in another table. Table names are made unique through naming conventions, not foreign keys. While foreign keys can influence performance, their main purpose is not to increase speed. They do not provide encryption for column data.
Which keyword is used to sort the result set in SQL queries?
Explanation: ORDER BY is the correct keyword used in SQL to sort records by one or more columns. GROUP ON is not an SQL keyword, and GROUP BY is used for grouping, not sorting. SORT BY and FILTER BY are common phrases but are not valid SQL commands.
Which database design principle reduces duplicate data by dividing information into multiple related tables?
Explanation: Normalization reduces data redundancy by structuring data into related tables. Denormalization does the opposite, potentially increasing redundancy for performance. Aggregation refers to summarizing data but is not primarily about redundancy. Minimization is not a standard database design principle.
If a column is defined as NOT NULL in a table, what does this constraint enforce?
Explanation: The NOT NULL constraint ensures that each record has a value in the specified column. Uniqueness is enforced with UNIQUE or PRIMARY KEY, not NOT NULL. Numeric type is set by the data type, not the NOT NULL constraint. Referencing another table is handled by foreign keys.
Which of the following is the correct syntax to insert a new record with values into a table named 'Products'?
Explanation: INSERT INTO is the correct SQL syntax for adding a new record with specified column values. ADD TO, NEW ROW, and APPEND are incorrect phrases for data insertion, despite sounding plausible.
Which SQL keyword is used to return only distinct (non-duplicate) values from a column?
Explanation: DISTINCT is the correct SQL keyword for retrieving unique values from a column and eliminating duplicates. UNIQUE is a constraint for column values, not a keyword for selection. DIFFERENT and SINGLE are not recognized in SQL for this purpose.
Which table structure is commonly used to represent a many-to-many relationship between Books and Authors?
Explanation: A junction (or linking) table with BookIDs and AuthorIDs allows mapping multiple authors to multiple books. Combining all books and authors in one table as columns is inefficient and unscalable. Unrelated tables do not establish a many-to-many relationship. A view listing only author names does not represent the relationship.
What is the main function of the WHERE clause in a SQL SELECT statement?
Explanation: The WHERE clause is used to filter rows in a result set based on specific conditions. It does not determine the output format or join tables; joining is done with JOIN statements. Updating rows is performed using the UPDATE statement, not the WHERE clause itself.