Sunteți pe pagina 1din 5

Explain the concept of Foreign Key. How a foreign key differs from a Primary Key?

Can the Foreign Key accept


nulls?
Answer
Foreign Key:
A foreign key is a column in a table where that column is primary key of another table, which means that any
data in a foreign key column must have corresponding data in the other table where that column is the primary
key. Whereas primary key is a column or set of columns that uniquely identifies the rest of the data in any given
row.
For e.g consider a Table:
Students ID
Student
Year of
Subject enrolled In
number
name
course
1245

Sanjay

Mathematics

1246

Vijay

Science

1247

Jameel

Political science

1248

Nitesh

Arts

In the above table Student ID number is the primary key as this uniquely identifies that row. This means no
two rows can have the same Student ID number and is two students have the same name then Student ID
number ensures that those two students are not same.
Therefore if this Student ID number is used as a primary key for some other table then this ID is the foreign
key. No component of the primary key can be null whereas in the case of foreign key there is no integrity rule
saying that no component of the foreign key can be null. Therefore foreign key accepts null.

With a necessary example explain (i) Basic Constructs of E-R Modeling (ii) E-R Notations.
Answer

Entity name
Entity

Department
DepID

Relationship name

One

Project

Many
ProjectID

vlanages

Relationship
Attribute name
Mandatory existence

Optional existence

ER NOTATION

Constructs of E-R Modeling: ER modeling views the real worlds as a constructs of entities and association
between entities.
Entities: Entities are the principal data object about which information is to be collected. It is classified as
independent or dependent. An independent entity is one that does not rely on another for identification
whereas dependent is one that relies on another for identification. Special entity types are associative, and
subtype entities.
Relationship: a relationship represents as association between two or more entities. Relationships are classified
in terms of degree, connectivity, cardinality and existence.
Attributes: Attributes describes the entity of which they are associated. Attributes can be classified as
identifiers or descriptors. Identifiers, or keys, uniquely identify an instance of an entity. A descriptor describes a
non-unique characteristic of an entity instance.
Degree of relationship: It is the number of entities associated with the relationship
Connectivity and cardinality: It describes the mapping of associated entity instance in a relationship. The value
of connectivity are one-to-one (1: 1), one-to-many (1 : N), Many-to-Many (M : N).
Direction: Direction of a relationship indicates the originating entity of a binary relationship the entity from
which a relationship originates is the parent entity and entity where relationship terminates is the child entity.
Existence: Existence denotes whether the existence of an entity instance is dependent upon the existence of
another, related, entity instance.
ER Notations: Basic ER notations are as:
1) Entities are represented by labeled rectangles.
2) Relationships are represented by a solid line connecting two entities.
3) Attributes when included are listed inside the entity rectangle. Attributes which are identifiers are
underlined
4) Cardinality of many is represented by a line ending in a crows foot. If the crows foot is omitted, the
cardinality is one.
5) Existence is represented by placing a circle or a perpendicular bar on the line.

Explain the first 3 Normal Forms taking the help of an un-normalized relation and reducing it to 3 NF.
Answer
Normalization is the process of efficiently organizing data in a database.
First Normal Form (1NF): A relation which contains a repeating group is called an un-normalized relation.
Therefore a relation is said to be in first normal form if it does not contain repeating groups.
Second Normal Form (2NF): A relation is said to be in 2NF if it is in 1NF and no non-key attribute is functionally
dependent on only a portion of the primary key. For example consider a table Software.
Software
packid

packname tagnumber

cost

cmpid

MST

microsoft

11382

500

M223

DBS

Database

11256

400

S456

FP1

IBM

11695

900

D765

FP1

IBM

11584

700

S098

As we can see that in the column packid FP1 occurs several times. This causes several problems like wastage of
memory and update, inconsistent data addition and deletions problems. Therefore a relation is said to be in
2NF if it is in 1NF and contains no partial dependencies, so software table is currently is not in 2NF, Method to
convert it into 2NF is as follows.

For each subset of the set of attributes , which make up the primary key start a relation with this subset as its
primary key so for software relation , now place the other attributes in such a way that we obtain minimal
relation for which these subsets of attributes are primary key, so we obtain
(packid, packname)
(tagnumber,cmpid)
(packid,tagnumber,cost)
So each of above relation can now be given a name which is descriptive of the meaning of the relation e.g.
PACK, COMP, SOFT.
Third Normal Form (3NF): A relation is said to be in 3NF if it is in 2NF and if the only determinants it has are
candidate keys. Where an attribute which determines another attribute is called determinant.

Explain the concept of Data Mining? How it is related with data warehouse.
Answer
Data mining: Data mining is basically used to discover new rules and patterns from the supplied data. It is also
said that it addresses inductive knowledge. Following are the five knowledge discovered during data mining
Association rule: these rules correlate the presence of a set of items with another range of values for another
set of variables.
Classification hierarchies: the goal is to work from an existing set of events or transactions to create a hierarchy
of classes.
Sequential patterns: A sequence of actions or events is sought.
Patterns with time series: Similarities can be detected within position of time series of data, which is a sequence
of data taken at regular interval such as daily sales or daily closing stock prices.
Clustering: A given population of events can be partitioned into set of similar elements.
As data mining concept can be applied to large variety of decision making contexts in business, some particular
areas are Marketing, Finance, Manufacturing, Health care
Further Data mining is related with data warehouse as follows:
As goal of data warehouse is to support decision making with data. Data mining can be used in conjunction with
a data warehouse to help with certain types of decisions. Data mining can be applied to operational databases
with individual transactions. To make data mining more efficient, the data warehouse should have an
aggregated or summarized collection of data. Data mining helps in extracting meaningful new patterns that
cannot be found by merely querying or processing data in the data warehouse. Data mining application should
therefore be strongly considered early, during the design of the data warehouse. Also data mining tools should
be designed to facilitate their use in conjunction with data warehouse. In fact for very large databases running
into terabytes of data, successful use of data mining applications will depend first on the construction of a data
warehouse.
Therefore data warehouse provides access to data for complex analysis, knowledge discovery and decision
making and they support high-performance on an organizations data and information whereas data mining is
used to discover new rules and patterns from the supplied data.

Write the SQL queries using Data Manipulation Language (DML) statements.
(a) Insert values into student table with field names using insert command
(b) Display the table student using select command
(c) Update student address in student table using update command.
(d) Delete a row from student table.
Answer
Creating a Table:
CREATE TABLE STUDENT
(
Student INT,
First name VARCHAR (20),
Last name VARCHAR (20),
Gender ENUM (M,F),
Address VARCHAR (100)
)
(a) Insert values into student table with field names using insert command
INSERT INTO STUDENT(StudentID,Firstname,Lastname,Gender,Address)VALUES(234,nikhil,singh,M,H-12 Delhi);
(b) Display the table student using select command
SELECT StudentID,Firstname,Lastname,Gender,Address FROM STUDENT;
(c) Update student address in student table using update command
UPDATE STUDENT address = H-29 new Delhi WHERE ITEM = H-12 Delhi;
(d) Delete a row from student table
DELETE FROM STUDENT WHERE studentID=234 AND first name = Nikhil AND last name = Singh ;

Create the payroll database considering table employee.


(a) Do simple queries on the above database.
i. List all information of the above both tables.
ii. List the empno, ename, jobtitle,and hiredate of employee from the employee table.
(b) List the name, salary of the employees who are clerks.
(c) List the name,job,salary of every employee joined on certain date. (say december 17,1980)
(d) List name and annual salary of all the employees.
(e) List the employees who have salary between certain range (say between Rs. 1000 & 2000)

Answer
CREATE TABLE employee
(
emp_no INT
ename
VARCHAR(20)
job title VARCHAR(16)
salary
INT
hiredate DATE
);
(a) (1) List all information of the above both tables.
SELECT * FROM employee;
(2) List the empno, ename, jobtitle,and hiredate of employee from the employee table
SELECT empno, ename, jobtitle, hiredate FROM employee;
(b) List the name, salary of the employees who are clerks
SELECT ename, salary FROM employee WHERE job title = clerks;
(c) List the name,job,salary of every employee joined on certain date. (say december 17,1980)
SELECT ename, job title, salary FROM employee WHERE hiredate = december 17,1980;
(d) List name and annual salary of all the employees.
SELECT ename, SUM(salary) FROM employee GROUP BY ename;
(e) List the employees who have salary between certain range (say between Rs. 1000 & 2000)
SELECT ename FROM employee WHERE salary BETWEEN 1000 AND 2000;

S-ar putea să vă placă și