Relational databasesLearning objectives
11.4.1.1 describe relational databases and their purpose 11.4.1.2 use the terms "table", "attribute", "record", and "index" to describe databases 11.4.1.3 explain the difference between primary, foreign and composite keys 1. What is a relational database?
It helps a program store, retrieve and update related information. A school club database can answer: Who joined Robotics? or Which clubs did student 101 join? A well-designed database can reduce repeated facts: store a club's name once in Clubs and refer to it by ClubID in Enrolments. Key constraints help keep these references valid. Open the original lesson video on YouTube. Database, DBMS and phpMyAdminThe database is the organised data. A DBMS is software that manages databases; MySQL and MariaDB are examples. phpMyAdmin is a web interface for administering MySQL or MariaDB. XAMPP is a local development package containing Apache, MariaDB, PHP and Perl. XAMPP downloads · About phpMyAdmin. 2. Table, attribute and recordThe following school club data are illustrative. Each table describes a type of thing, such as students, clubs or enrolments.
Select a button to highlight a component. StudentID is the chosen primary key. Use precise language: FirstName is an attribute; Dana is an attribute value. The whole row 3. Primary, foreign and composite keys
Primary and foreign describe a key's role. Composite describes its use of multiple attributes. One key can therefore be both primary and composite.
In this system, a student may join several clubs, but can join each particular club only once. StudentID 101 repeats, and ClubID C01 repeats. Each complete pair is different. One composite primary key: (StudentID, ClubID) identifies an enrolment. Its two attributes also act as two foreign keys. A table has at most one primary-key constraint, which may contain several attributes. Match the ID values to find the student's enrolments and club names. What happens when a referenced record is missing?A non-NULL foreign-key value must match a referenced key. StudentID 999 cannot be used here because Students has no such record. A foreign key can allow NULL when the schema permits it. In this example, both foreign keys are also components of the primary key, so neither can be NULL. Deletion of referenced records follows rules defined in the schema. 4. What is an index?
Like a book index, it provides a route to relevant entries. An ordinary index can contain repeated search values. It needs storage and maintenance when the data changes; a DBMS decides whether using it will help a particular query. A primary key defines record identity. An index supports lookup; a DBMS may use a unique index to enforce a primary key. Row numbers displayed by an interface are only display labels.
This simplified lookup guide shows references to records, not row positions or measured query times. 5. Key laboratoryTry adding an enrolment. The model checks the two foreign keys and the composite primary key. The example Students and Clubs tables stay unchanged. Interactive controls require JavaScript. If this notice remains visible, the script is not running. The theory, tables and answer explanations are still available. Try (104, C02), then repeat it. Next try a missing ID or NULL.
This is a classroom model of key constraints. Lab changes last until reset or page reload. 6. ExercisesThere are eight activities: the two original LearningApps exercises and six checked tasks below. LearningApps results are separate from the progress counter. Ex. 1 · Terms and definitions (LearningApps)Ex. 2 · Components of a database table (LearningApps)Completed: 0 / 6 checked tasks
Answers and progress are kept in this browser when storage is available. They are not sent to a teacher. Clear answers and progress for the six checked tasks? Ex. 3 · Purpose of a relational database Not checkedEx. 4 · Table, attribute, record and index Not checkedEx. 5 · A suitable primary key Not checkedEx. 6 · Follow foreign keys Not checkedEx. 7 · A composite primary key Not checkedEx. 8 · An index and its trade-off Not checked7. Exam-style practiceWrite complete explanations before opening the suggested answers. These are practice questions written for this lesson. 1. Describe a relational database and one benefit for the club system.It organises data in related tables of rows and columns. Matching keys let the system combine information, for example student names and the clubs they joined. Storing club details once can reduce repeated data. 2. Explain why StudentID alone cannot identify each Enrolments record.A student can join several clubs, so StudentID repeats in Enrolments. The combination (StudentID, ClubID) identifies one enrolment because each student can join a particular club only once. 3. Explain the difference between a primary key, a foreign key and an index.A primary key identifies each record uniquely. A foreign key references a key in a related table and keeps the link valid. An index is a lookup structure that can improve searches, with storage and maintenance costs. Language support for explanations
Further study: Primary key & Composite key · Data types. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Просмотров: 14913 | | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Всего комментариев: 0 | |