Explore the essential concepts of primary keys, partition keys, and clustering keys used in database design and data modeling. This quiz covers key definitions, differences, and practical uses to strengthen your understanding of unique identification and organization of records.
In a relational database table, what is the main purpose of a primary key column such as 'student_id' in a 'Students' table?
Explanation: A primary key uniquely identifies each row, ensuring no two rows have the same value in the primary key column. Allowing duplicate values would defeat its purpose (option B). Determining display order (option C) is not its role, and holding foreign key references (option D) is done by foreign keys, not primary keys.
What is the function of a partition key in a distributed database storing 'orders' data?
Explanation: The partition key is used to distribute or locate data across different nodes or partitions. It does not randomly generate numbers (option B), nor offer a description (option C). Although used for partitioning, it is not specifically a sorting key (option D).
When designing a composite primary key, what role does the clustering key play in an 'events' table with 'event_date' and 'location'?
Explanation: A clustering key dictates how rows are ordered logically within a partition, aiding in efficient querying. It does not enforce null constraints (option B), uniqueness globally (option C), or encryption (option D), which are managed by other mechanisms.
Which characteristic must be true for any primary key defined in a table such as 'Employee'?
Explanation: Primary keys must be non-null to ensure every row is identifiable. They are not required to be numeric (option B). References to other tables are handled with foreign keys (option C), and primary keys are not optional if data integrity is essential (option D).
In a table with a composite primary key consisting of 'user_id' and 'order_id', what is typically the difference between the partition key and the clustering key?
Explanation: Partition keys distribute data across storage nodes, while clustering keys sort data within partitions. They do not serve the same function (option B), clustering keys do not manage global uniqueness (option C), and partition keys are not just for sorting (option D).
Which column(s) would be the best choice for a primary key in a 'Countries' table with columns: name, code, population, and region?
Explanation: Country codes are globally unique identifiers, fitting the primary key requirement. Population values are not unique (option B), regions can repeat (option C), and mixing name with population can't guarantee uniqueness either (option D).
What will most commonly happen if you try to insert two rows with the same primary key value in a database table?
Explanation: Primary keys must be unique, so duplicates result in an error. Databases do not allow silent acceptance (option B), random selection (option C), or silent updates without notice (option D), as these undermine data integrity.
Why might a table for 'CourseEnrollments' use a composite primary key made up of 'student_id' and 'course_id'?
Explanation: A composite key of student_id and course_id ensures the same student cannot enroll in the same course more than once. It does not make course_id unique overall (option B). The key itself doesn't limit student counts (option C), nor does it permit duplicates (option D).
Which scenario demonstrates an incorrect use of a clustering key in a table partitioned by 'user_id'?
Explanation: A clustering key should provide variety to order data meaningfully; a constant value like 'status' is unsuitable as it cannot effectively sort or organize data. 'Timestamp', 'order_number', and 'message_id' all introduce variety and usefulness for sorting (options B, C, and D).
How does a primary key differ from a foreign key in the context of database relationships?
Explanation: The primary key provides unique identification within its table, while a foreign key establishes a link to a primary key in another table to maintain relational integrity. Both keys are not required everywhere (option B), and primary keys do not allow duplicates (option C). Numeric-only requirements (option D) are not accurate for either key.