Referential Integrity:
Referential integrity is how the databases are linked together to make sure that the references between are valid and intact. Referential integrity is usually enforced by the combination of a primary and a foreign key. For example, customer numbers in a customer file are the primary keys, and customer numbers in the order
file are the foreign keys. If a customer record is deleted, the order records must also be deleted; otherwise they are left without a primary reference. There are many benefits of defining referential integrity in a database: improved data quality, faster development, fewer bugs and consistency across applications.
Primary Key: Every time you put in data inside a relational table, you would need an easy way to identify each row that will be stored in the table. For that you would need to use a primary key. The value that this key holds should be unique for each record in the database. For example if you were to have a table named 'Employees' that contains personal information, you'd need to select an appropriate primary key that would uniquely identify each employee. Typing in the name wouldn't be really appropriate because there can obviously be people with the same names involved. So you would use an unique employee ID. That way you could list more and more people in your table using little unique ID's. Also that way you won't have anything mixed up.
Foreign Key: The foreign key is a unique field in a database that another table will use to access information, such as a "look up" table. It's information related with a primary key in another table. It makes it easier to find information about a certain aspect.
One-to one relationships: In one-to one relationship, each row is in one database table is linked to 1 and only 1 other row in another table. In one-to one relationship between table A and table B, each row in table A is linked to one of the rows in table B. The number of rows in table A must be equal to the number of rows in table B. For example, a person would have only one specific identity document that will belong only to them. Therefore one of the tables will have the name of the person and it would be linked with their ID document. No other links would be involved.
One-to many relationships: Those are the most common types of the database relationships. They occur when each record in the first table corresponds to one or more records in th second table but each record in the second table corresponds to only one record in the first table. For example in elementary school the relationship between the teacher and the students will most likely be one-to many, since the class has one teacher but the teacher might have multiple classes.
Many to many relationships: Those occur when each record in the first table corresponds to 2 or more records in the second table and the each record in the second table can correspond to 2 or more records in the first table. For example the relationship between a teacher and courses would most likely be many-to many since most teachers can teach more than one course and each course can have more than one teacher.
All you now need for M1 is to describe the different types of relationships and give examples.
ReplyDeleteExcellent. M1 complete.
ReplyDelete