0% found this document useful (0 votes)
16 views2 pages

Primary vs Foreign Key Explained

Uploaded by

varsha Tamhane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Primary vs Foreign Key Explained

Uploaded by

varsha Tamhane
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1) State the relationship and difference between a primary and foreign key?

Ans) Relationship : A primary key is used to assure the value in the particular column is unique. The
foreign keyprovides the link between the two tables.

Difference: 1) A primary key generally focuses on the uniqueness of the table. It assures the value in the
specific column is unique. A foreign key is generally used to build a relationship between the two tables.

2) Table allows only one primary key. Tables can allow more than one foreign key.

3) The primary key doesn’t allow null values. Foreign key accepts multiple null values.

4) It can identify the record uniquely in the database table. A foreign key is a field in the table that is the
primary key in another table.

5) In the primary key, the value cannot be removed from the parent table. In this, the value can be
deleted from the child table.

[Link] many types of relationships can be created in Base? Explain each of the them.

[Link] are set up between the tables to control data redundancy and inconsistency. There are
three types of relationships which can be created in tables:

1. ONE to ONE 2. ONE to MANY OR MANY to ONE 3. MANY to MANY


In One-to-One type of relationship, one specific record of a master table has one and only one
corresponding record in the transaction table.
• In One-to-Many type of relationship, one specific record of the master table has more than
one corresponding records in the related transaction table.
• In Many-to-Many type of relationship, there are multiple records in the master table that
correspond to multiple records in the transaction table.
• According to the principle of referential integrity, no unmatched foreign key values should
exist in the database.
[Link] do you mean by Sorting? In how many ways it can be done?
Ans) Sorting means to arrange the data in a particular sequence. It can be done in two ways: a)
Ascending order b) Descending order
[Link] Referential Integrity with the help of an example.
Ans) Referential integrity is used to maintain accuracy and consistency of data in a relationship.
Referential integrity helps to avoid:
• Adding records to a related table if there is no associated record available in the primary key
table.
• Changing values in a primary if any dependent records are present in associated table(s).
• Deleting records from a primary key table if there are any matching related records available
in associated table(s).
According to the principle of referential integrity, no unmatched foreign key values should exist
in the database. That means if a record, say Admission No as 1001 is not present or deleted in
the master table (Student_Details) of Student database, then there should be no record with
Admission no as 1001 in the transaction table (Student_Result) as well. Similarly, in Ruhi’s Sports
Day database, if a particular category of sports, say C003 is deleted from the master table
EventCategory, then there should be no record with Category as C003 in the transaction table.
Likewise, if any student leaves the school and his record is deleted from Student_Details table,
then there is no question of his appearing for exams and having a result. Hence corresponding
record in the transaction table (Student_Result) should either have NULL value or should be
deleted.
6. Explain Many to Many relationships.
In this type of relationship, there will be multiple records in the master table that correspond to
multiple records in the transaction table as well. Generally this type of relationship is set when
certain records have to be saved more than once in both the related tables. For example, a
teacher in a school may hold multiple responsibilities such as class teacher, an activity in charge
or examination in-charge. For each responsibility the teacher might be attached with multiple
students. So this type of relationship will be many to many relationship. Similarly a shopkeeper
may sell multiple products to multiple customers. So many-to-many relationship exists between
a product and a custom
[Link] a query? What is the need of creating a query in a database?
Ans) A query is a request for data result , and for action of data . You can use a query to answer
a simple question, to perform calculation, to combine data from different tables, or even to add,
change or delete table data
1) Explain the three different datatype objects ?
Ans) Tables: A table is a set of data elements (values) that is organized using a model of
vertical columns(which are identified by their name) and horizontal rows. A table has a
defined number of columns, but can have any number of rows. Each row is identified by the
values appearing in a particular column identified as a unique key index or the key field.
Columns or Fields or Attributes: A column is a set of data values of a particular simple type,
one for each row of the table. The columns provide the structure according to which the
rows are composed. For example, cFirstName, or cLastName are fields in a row.
Rows or Records or Tuples: A row also called a Record or Tuple represents a single, data
item in a table. In simple terms, a database table can be visualized as consisting of rows and
columns or fields. Each row in a table represents a set of related data, and every row in the
table has the same structure.

You might also like