SQL Notes - 2
SQL Notes - 2
Ans- There are four types of operations that we can perform on tables-
Ans- Referential Integrity (RI) is a rule in RDBMS. It states that a foreign key must have a matching primary key, i.e., all its
references must be valid and the users cannot accidentally delete or change the data. It ensures the accuracy and
consistency of the data within a relationship, and prevents the users to enter the inconsistent data.
Referential Integrity does not allow you to enter a new record in the child table (a table that contains the foreign key) for
which you do not have any matching record in the parent table (a table that contains the primary key). However,if you
make any change in the primary key field value, the same must be applied in the foreign key value. The samerestriction
also applies on the the foreign key.
Consider the following example, where Customer is the parent table with the primary key CustomerID and Balance is the
child table with the foreign key CustomerID. The child table (Balance table) is violating the Referential Integrity rule
becausethere is no matching record for CutomerId 105 in the primary key field of the parent table.
CustomerId Balance
Violating
Referential 101 25000
Integrity
102 5000
103 1000
104 5000
105 5000
What is RELATIONSHIP-
Ans- A relationship is a link that associates a field in one table with a field in another table. In Base, you can store data in
multiple tables. To bring that information together, you need to define a relationship among the tables.
A relationship works by matching a field with the same name in both the tables: In most of the cases, these matching
fields are the Primary key in one table and Foreign key in the other table.
TYPES OF RELATIONSHIPS-
In relational database, there are three types of relationships that can exist between a given pair of tables as listed below:
One-to-One
One-to-Many
Many-to-Many
One-to-One: In this type of relationship, a record in a table can have only one matching record in another table, and vice
versa. For example, in UIDAI database, each person has only one Aadhaar number, and each Aadhaar number is
assigned to only one person.
One-to-Many: In this type of relationship, a record of Table A is associated with several matching records of Table B.
However, the record from the Table B is associated with only one record of Table A. For example one class consists of
multiple students, and a set of students belongs to a class only.
Many-to-Many: In this type of relationship, many records are associated with many records of another table, and vice
versa. For example, a group of students can be taught by many teachers, and teachers can teach different groups of
students.
Ans.
o Open a database and select Tables in the Database Objects Pane. You will see a list of tables.
o Select the Students table and click on the Add button to add it in the Relationship window.
o Similarly, add the Fee table in the Relationship window.
o Click on the Close button to close the Add Tables dialog box.
o Drag the primary key of the parent table (Student table) and drop it over the same field in the child table
(Fee table). Notice, a relationship has been created between both the tables using the the Roll Number
field .
o Click on the Save button in the File menu to save the relationship.
Ques – Explain FIELD PROPERTIES-
Ans- A field property applies to a particular field in a table. The properties for each field are set in the Table
Design View using the Field Properties pane.
Following are the different properties that you assign while creating fields.
AutoValue: If set to Yes, the values for this data field is generated by the database engine.
Entry required: If set to Yes, this field must not be empty.
Length: It specifies the maximum number of characters for the data field.
Default value: It specifies the default value for a Yes/No field.