Question

In: Computer Science

Using a simple relation of your own choice and example, explain Entity Integrity and Referential Integrity.

Using a simple relation of your own choice and example, explain Entity Integrity and Referential Integrity.

Solutions

Expert Solution

Entity Integrity:
Entity integrity ensures each row in atable is a uniquely indentfiable entity. you can apply entity integrity to a table by specifing a PRIMARY KEY and UNIUQE KEY constraint.Mainly Entity integrity referred as primary key.
PRIMARY KEY: This is used avoid duplicates and nulls.this will works as combination of unique and not null.
primary key always attached to the parent table.
A table should contain only one primary key.
it can apply on any datatype column like integer,character,decimal datatypes...etc
UNIQUE KEY: this is used to avoid duplicates but it allow nulls.


Example: 1.We create a table

create table Emp(EID int Primary key,Ename varchar(40),Salary money)

2.insert values into table

insert into Emp values(101,'Raju',15000)

insert into Emp values(102,'suresh',25000)

insert into Emp values(101,'jon',35000)

Referntial Integrity:
Referntial integrity ensures the relationships between tables remain preserved as data is inserted,deleted and modified.You can apply referntial integrity using a FOREIGN KEY constraint.

Foreign key:One of the most importent concepts in database is creating relation ships between database tables.these relationships provide a mechanism for linking data stored in multiple tables and retriving it in an efficient manner.
In order to create a link between two tables we must specify aforeign key in one table that referces a column in another table.
Foreign key constraint is used for relating or binding two tables with each other and then verifies the existence of one table data in the other.
to impose a foreign key constraint we require the following things.
we require two tables for binding with each other and those two tables must have a comman column for linking the tables.
Example:
To create department table:
create table Department(Deptno int primary key,Dname varchar(40),Location varchar(max))
Insert records into the Department table:

insert into Department values(10,'Sales','Hyderabad')
insert into Department values(20,'Production','Chennai')
insert into Department values(30,'Finance','Mumbai')

To create Employee table (Child table):

create table Employee(EID int,Ename varchar(40),Salary money, Deptno int foreign key refernces Department(Deptno))

Insert records into Employee table:

insert into Employee values (101,'sai',35000,10)
insert into Employee values (102,'pavan',45000,20)
insert into Employee values (103,'kamal',74000,30)

Foregin Key rules:

1.Can not insert a value into the foregin key column provided that value is not existing under the refernce key column of the parent table.
2.Can nit update the refernce key value of aparent table provided that value has corresponding child record in the child table with out addressing what to do with the child record.
3.We can not delete a record from the parent table provided that records refernce key value has child record in the child table with out addressing what to do with the child record.
If we wnat to delete or update a record in the parent table when they have corresponding child records in the child table we are provide with a set of rules to perform delete and update operations known as cascade rules.

On delete cascde: It is used to delete a key value in the parent table which reference by the foreign key in other table all rows that contains those foreign keys in child table are also deleted.

on Update cascade: It is used to update a key value in the parent table which is referenced by foreign key in other table all rows that contanins those foreign keys in child table also updated.

If we apply this while creating the child table like below

create table Emp(EID int ,Ename varchar(40),salary money,Deotno int foreign key refernces Department(Deptno) on delete cascade on update cascade)


Related Solutions

QUESTION 1 a. What are referential integrity constraints? Please explain with an example. b. Explain with...
QUESTION 1 a. What are referential integrity constraints? Please explain with an example. b. Explain with an example the GROUP BY/HAVING clause
5.8. Discuss the entity integrity and referential integrity constraints. Why is each considered important? 5.9. Define...
5.8. Discuss the entity integrity and referential integrity constraints. Why is each considered important? 5.9. Define foreign key. What is this concept used for? 5.10. What is a transaction? How does it differ from an Update operation?
Using a business/organization of your choice, explain how that entity segments its market.
Using a business/organization of your choice, explain how that entity segments its market.
Answer these theory questions: a. Explain the referential integrity rule. Provide a suitable situation when the...
Answer these theory questions: a. Explain the referential integrity rule. Provide a suitable situation when the referential integrity constraint is violated. b. Consider a relation named STUDENT_ ACCOMMODATION (StudentID, Buidling, AccommodationFee) as shown in the figure below. Explain why this relation is in 2NF but not in 3NF.              StudentID Building AccommadtionFee 101 Alpha $320 102 Betta $250 103 Alpha $320 104 Betta $250 105 Gemma $400 c. Explain the purpose of transaction logs and checkpoints. d. Compare and contrast Data...
indicate whether the sample is biased or unbiased and explain your choice using your own words...
indicate whether the sample is biased or unbiased and explain your choice using your own words and in complete sentences. In some cases, it may be appropriate to answer "not sure" because there is insufficient information to make a judgement. In these cases, if any occur, describe any additional information that you would like to have before deciding whether is biased or unbiased. In each of these excerpts, it is important to realize that you cannot assume that a sample...
Explain in detail an example of scarcity, choice and opportunity cost from your own life. How...
Explain in detail an example of scarcity, choice and opportunity cost from your own life. How can tradeoffs such as these can be illustrated by the Production Possibilities Frontier Model? Be sure to explain the graph in detail and how it relates to your analysis. 200 word
Using an example of your choice, explain how, despite the Coase Theorum, the allocation of rights...
Using an example of your choice, explain how, despite the Coase Theorum, the allocation of rights can: Affect the distribution of income and Affect market demand for different products
Using an example of your choice, explain how, despite the Coase Theorum, the allocation of rights...
Using an example of your choice, explain how, despite the Coase Theorum, the allocation of rights can: Affect the distribution of income and Affect market demand for different products
Using an example of your own, explain the difference between the calculations ₈C₃ ₈P₃?
Using an example of your own, explain the difference between the calculations ₈C₃ ₈P₃?
Using an example of a company of your choice, discuss the functions of management
Using an example of a company of your choice, discuss the functions of management
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT