Friday, 31 July 2015

DKNF

Domain-key normal form (DK/NF) is a normal form used in database normalization which requires that the database contains no constraints other than domain constraints and key constraints.
A domain constraint specifies the permissible values for a given attribute, while a key constraint specifies the attributes that uniquely identify a row in a given table.
The domain/key normal form is achieved when every constraint on the relation is a logical consequence of the definition of keys and domains, and enforcing key and domain restraints and conditions causes all constraints to be met. Thus, it avoids all non-temporal anomalies

DDL , DML ,DCL

What are the difference between DDL, DML and DCL commands?


DDL


Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
  • CREATE - to create objects in the database
  • ALTER - alters the structure of the database
  • DROP - delete objects from the database
  • TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
  • COMMENT - add comments to the data dictionary
  • RENAME - rename an object

DML


Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:
  • SELECT - retrieve data from the a database
  • INSERT - insert data into a table
  • UPDATE - updates existing data within a table
  • DELETE - deletes all records from a table, the space for the records remain
  • MERGE - UPSERT operation (insert or update)
  • CALL - call a PL/SQL or Java subprogram
  • EXPLAIN PLAN - explain access path to data
  • LOCK TABLE - control concurrency

DCL


Data Control Language (DCL) statements. Some examples:
  • GRANT - gives user's access privileges to database
  • REVOKE - withdraw access privileges given with the GRANT command

TCL


Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
  • COMMIT - save work done
  • SAVEPOINT - identify a point in a transaction to which you can later roll back
  • ROLLBACK - restore database to original since the last COMMIT
  • SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

WHAT DO U MEAN BY RELATION SHIP TYPE?

Q-TYPE OF RELATIONSHIP IN DATA BASE ?
 ANS-

Explain the types of relationships in database. 

One-to-one
One to one is implemented using single table by establishing relationship between same type of columns in a table. 
One-to-many
Implemented using two tables with primary key and foreign key relationships.
Many-to-many
Implemented using a junction table.
The keys from both the tables form composite primary key of the junction table 

 OR WE CAL CLASSIFY RELATIONSHIP AS
 (A)- UNARY RELATIONSHIP -
        RELATISONSHIP WITHIN  SAME TABLE 
(B) - BINARY RELATION SHIP 
     RELATION SHIP B/W TWO TABLES 
(C) TERNARY RELATIONSHIP 

Q- WHAT DO U MEAN BY DEGREE OF RELATIONSHIP ?
ANS- No of entity participate in the relationship  is called degree of the relationship..

SYMBOLS FOR ER DIAGRAM

E-R Diagram

ER-Diagram is a visual representation of data that describes how data is related to each other.
example of er-diagram

Symbols and Notations

ER diagrams symbols
ER diagrams symbols

Components of E-R Diagram

The E-R diagram has three main components.

1) Entity

An Entity can be any object, place, person or class. In E-R Diagram, an entity is represented using rectangles. Consider an example of an Organisation. Employee, Manager, Department, Product and many more can be taken as entities from an Organisation.
Entity example

Weak Entity

Weak entity is an entity that depends on another entity. Weak entity doen't have key attribute of their own. Double rectangle represents weak entity.
weak Entity example

2) Attribute

An Attribute describes a property or characterstic of an entity. For example, Name, Age, Address etc can be attributes of a Student. An attribute is represented using eclipse.
attribute example

Key Attribute

Key attribute represents the main characterstic of an Entity. It is used to represent Primary key. Ellipse with underlying lines represent Key Attribute.
key attribute example

Composite Attribute

An attribute can also have their own attributes. These attributes are known as Composite attribute.
composite attribute example

3) Relationship

A Relationship describes relations between entities. Relationship is represented using diamonds.
relationship example
There are three types of relationship that exist between Entities.
  • Binary Relationship
  • Recursive Relationship
  • Ternary Relationship

Binary Relationship

Binary Relationship means relation between two Entities. This is further divided into three types.
  1. One to One : This type of relationship is rarely seen in real world.
  2. one-to-one example
    The above example describes that one student can enroll only for one course and a course will also have only one Student. This is not what you will usually see in relationship.
  3. One to Many : It reflects business rule that one entity is associated with many number of same entity. For example, Student enrolls for only one Course but a Course can have many Students.
  4. one-to-many example
    The arrows in the diagram describes that one student can enroll for only one course.
  5. Many to Many :
  6. many-to-many example
    The above diagram represents that many students can enroll for more than one courses.

Recursive Relationship

When an Entity is related with itself it is known as Recursive Relationship.
recursive relationship example

Ternary Relationship

Relationship of degree three is called Ternary relationship

Generalization

Generalization is a bottom-up approach in which two lower level entities combine to form a higher level entity. In generalization, the higher level entity can also combine with other lower level entity to make further higher level entity.
generalization

Specialization

Specialization is opposite to Generalization. It is a top-down approach in which one higher level entity can be broken down into two lower level entity. In specialization, some higher level entities may not have lower-level entity sets at all.
Specialization

Aggregration

Aggregration is a process when relation between two entity is treated as a single entity. Here the relation between Center and Course, is acting as an Entity in relation with Visitor.
aggregration



QUESTIONS



1. What is database?
A database is a collection of information that is organized so that it can easily be accessed, managed, and updated. In one view, databases can be classified according to types of content: bibliographic, full-text, numeric, and images.
In computing, databases are sometimes classified according to their organizational approach. The most prevalent approach is the relational database, a tabular database in which data is defined so that it can be reorganized and accessed in a number of different ways. A distributed database is one that can be dispersed or replicated among different points in a network. An object-oriented programming database is one that is congruent with the data defined in object classes and subclasses.

2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications..

3. What is a Database system?
The database and DBMS software together is called as Database system.
4. What is extension and intension?
  1. Extension: It is the number of tuples present in a table at any instance. This is time dependent.
  2. Intension: It is a constant value that gives the name, structure of table and the constraints laid on it.

5 What is System R? What are its two major subsystems?
System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of existing system.
Its two subsystems are
  1. Research Storage
  2. System Relational Data System.
6 How is the data structure of System R different from the relational structure?
Unlike Relational systems in System R
  1. Domains are not supported
  2. Enforcement of candidate key uniqueness is optional
  3. Enforcement of entity integrity is optional
  4. Referential integrity is not enforced

7. What is Data Independence?
Data independence means that "the application is independent of the storage structure and access strategy of data". In other words, The ability to modify the schema definition in one level should not affect the schema definition in the next higher level.
Two types of Data Independence:
  1. Physical Data Independence: Modification in physical level should not affect the logical level.
  2. Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve



8. What is a view? How it is related to data independence?
A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary. 

Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence.
9. What is an Entity type?
It is a collection (set) of entities that have same attributes.
10. What is an Entity set?
It is a collection of all entities of particular entity type in the database.

11. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and constraints.


12. What is a Relation Schema and a Relation?
A relation Schema denoted by R(A1, A2, ..., An) is made up of the relation name R and the list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).

13. What is degree of a Relation?
It is the number of attribute of its relation schema.

14. What is Relationship?
It is an association among two or more entities.

 15 -How does Tuple-oriented relational calculus differ from domain-oriented relational calculus?
  1. The tuple-oriented calculus uses a tuple variables i.e., variable whose only permitted values are tuples of that relation. E.g. QUEL
  2. The domain-oriented calculus has domain variables i.e., variables that range over the underlying domains instead of over relation. E.g. ILL, DEDUCE

16. What is indexing and what are the different kinds of indexing?
Indexing is a technique for determining how quickly specific data can be found.
Types:
  1. Binary search style indexing
  2. B-Tree indexing
  3. Inverted list indexing
  4. Memory resident table
  5. Table indexing





TRANSACTION

Q-WHAT IS A TRANSACTION ?
ANS-transaction is a very small unit of a program and it may contain several lowlevel tasks. A transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability − commonly known as ACID properties − in order to ensure accuracy, completeness, and data integrity.



DBMS - Transaction


Advertisements


A transaction can be defined as a group of tasks. A single task is the minimum processing unit which cannot be divided further.
Let’s take an example of a simple transaction. Suppose a bank employee transfers Rs 500 from A's account to B's account. This very simple and small transaction involves several low-level tasks.
A’s Account
Open_Account(A)
Old_Balance = A.balance
New_Balance = Old_Balance - 500
A.balance = New_Balance
Close_Account(A)
B’s Account
Open_Account(B)
Old_Balance = B.balance
New_Balance = Old_Balance + 500
B.balance = New_Balance
Close_Account(B)

ACID Properties

A transaction is a very small unit of a program and it may contain several lowlevel tasks. A transaction in a database system must maintain Atomicity, Consistency, Isolation, andDurability − commonly known as ACID properties − in order to ensure accuracy, completeness, and data integrity.
  • Atomicity − This property states that a transaction must be treated as an atomic unit, that is, either all of its operations are executed or none. There must be no state in a database where a transaction is left partially completed. States should be defined either before the execution of the transaction or after the execution/abortion/failure of the transaction.
  • Consistency − The database must remain in a consistent state after any transaction. No transaction should have any adverse effect on the data residing in the database. If the database was in a consistent state before the execution of a transaction, it must remain consistent after the execution of the transaction as well.
  • Durability − The database should be durable enough to hold all its latest updates even if the system fails or restarts. If a transaction updates a chunk of data in a database and commits, then the database will hold the modified data. If a transaction commits but the system fails before the data could be written on to the disk, then that data will be updated once the system springs back into action.
  • Isolation − In a database system where more than one transaction are being executed simultaneously and in parallel, the property of isolation states that all the transactions will be carried out and executed as if it is the only transaction in the system. No transaction will affect the existence of any other transaction.

Serializability

When multiple transactions are being executed by the operating system in a multiprogramming environment, there are possibilities that instructions of one transactions are interleaved with some other transaction.
  • Schedule − A chronological execution sequence of a transaction is called a schedule. A schedule can have many transactions in it, each comprising of a number of instructions/tasks.
  • Serial Schedule − It is a schedule in which transactions are aligned in such a way that one transaction is executed first. When the first transaction completes its cycle, then the next transaction is executed. Transactions are ordered one after the other. This type of schedule is called a serial schedule, as transactions are executed in a serial manner.
In a multi-transaction environment, serial schedules are considered as a benchmark. The execution sequence of an instruction in a transaction cannot be changed, but two transactions can have their instructions executed in a random fashion. This execution does no harm if two transactions are mutually independent and working on different segments of data; but in case these two transactions are working on the same data, then the results may vary. This ever-varying result may bring the database to an inconsistent state.
To resolve this problem, we allow parallel execution of a transaction schedule, if its transactions are either serializable or have some equivalence relation among them.

Equivalence Schedules

An equivalence schedule can be of the following types −

Result Equivalence

If two schedules produce the same result after execution, they are said to be result equivalent. They may yield the same result for some value and different results for another set of values. That's why this equivalence is not generally considered significant.

View Equivalence

Two schedules would be view equivalence if the transactions in both the schedules perform similar actions in a similar manner.
For example −
  • If T reads the initial data in S1, then it also reads the initial data in S2.
  • If T reads the value written by J in S1, then it also reads the value written by J in S2.
  • If T performs the final write on the data value in S1, then it also performs the final write on the data value in S2.

Conflict Equivalence

Two schedules would be conflicting if they have the following properties −
  • Both belong to separate transactions.
  • Both accesses the same data item.
  • At least one of them is "write" operation.
Two schedules having multiple transactions with conflicting operations are said to be conflict equivalent if and only if −
  • Both the schedules contain the same set of Transactions.
  • The order of conflicting pairs of operation is maintained in both the schedules.
Note − View equivalent schedules are view serializable and conflict equivalent schedules are conflict serializable. All conflict serializable schedules are view serializable too.

States of Transactions

A transaction in a database can be in one of the following states −
Transaction States
  • Active − In this state, the transaction is being executed. This is the initial state of every transaction.
  • Partially Committed − When a transaction executes its final operation, it is said to be in a partially committed state.
  • Failed − A transaction is said to be in a failed state if any of the checks made by the database recovery system fails. A failed transaction can no longer proceed further.
  • Aborted − If any of the checks fails and the transaction has reached a failed state, then the recovery manager rolls back all its write operations on the database to bring the database back to its original state where it was prior to the execution of the transaction. Transactions in this state are called aborted. The database recovery module can select one of the two operations after a transaction aborts −
    • Re-start the transaction
    • Kill the transaction
  • Committed − If a transaction executes all its operations successfully, it is said to be committed. All its effects are now permanently established on the database system.

Crash Recovery

DBMS is a highly complex system with hundreds of transactions being executed every second. The durability and robustness of a DBMS depends on its complex architecture and its underlying hardware and system software. If it fails or crashes amid transactions, it is expected that the system would follow some sort of algorithm or techniques to recover lost data.

Failure Classification

To see where the problem has occurred, we generalize a failure into various categories, as follows −

Transaction failure

A transaction has to abort when it fails to execute or when it reaches a point from where it can’t go any further. This is called transaction failure where only a few transactions or processes are hurt.
Reasons for a transaction failure could be −
  • Logical errors − Where a transaction cannot complete because it has some code error or any internal error condition.
  • System errors − Where the database system itself terminates an active transaction because the DBMS is not able to execute it, or it has to stop because of some system condition. For example, in case of deadlock or resource unavailability, the system aborts an active transaction.

System Crash

There are problems − external to the system − that may cause the system to stop abruptly and cause the system to crash. For example, interruptions in power supply may cause the failure of underlying hardware or software failure.
Examples may include operating system errors.

Disk Failure

In early days of technology evolution, it was a common problem where hard-disk drives or storage drives used to fail frequently.
Disk failures include formation of bad sectors, unreachability to the disk, disk head crash or any other failure, which destroys all or a part of disk storage.

Storage Structure

We have already described the storage system. In brief, the storage structure can be divided into two categories −
  • Volatile storage − As the name suggests, a volatile storage cannot survive system crashes. Volatile storage devices are placed very close to the CPU; normally they are embedded onto the chipset itself. For example, main memory and cache memory are examples of volatile storage. They are fast but can store only a small amount of information.
  • Non-volatile storage − These memories are made to survive system crashes. They are huge in data storage capacity, but slower in accessibility. Examples may include hard-disks, magnetic tapes, flash memory, and non-volatile (battery backed up) RAM.

Recovery and Atomicity

When a system crashes, it may have several transactions being executed and various files opened for them to modify the data items. Transactions are made of various operations, which are atomic in nature. But according to ACID properties of DBMS, atomicity of transactions as a whole must be maintained, that is, either all the operations are executed or none.
When a DBMS recovers from a crash, it should maintain the following −
  • It should check the states of all the transactions, which were being executed.
  • A transaction may be in the middle of some operation; the DBMS must ensure the atomicity of the transaction in this case.
  • It should check whether the transaction can be completed now or it needs to be rolled back.
  • No transactions would be allowed to leave the DBMS in an inconsistent state.
There are two types of techniques, which can help a DBMS in recovering as well as maintaining the atomicity of a transaction −
  • Maintaining the logs of each transaction, and writing them onto some stable storage before actually modifying the database.
  • Maintaining shadow paging, where the changes are done on a volatile memory, and later, the actual database is updated.

Log-based Recovery

Log is a sequence of records, which maintains the records of actions performed by a transaction. It is important that the logs are written prior to the actual modification and stored on a stable storage media, which is failsafe.
Log-based recovery works as follows −
  • The log file is kept on a stable storage media.
  • When a transaction enters the system and starts execution, it writes a log about it.
<Tn, Start>
  • When the transaction modifies an item X, it write logs as follows −
<Tn, X, V1, V2>
It reads Tn has changed the value of X, from V1 to V2.
  • When the transaction finishes, it logs −
<Tn, commit>
The database can be modified using two approaches −
  • Deferred database modification − All logs are written on to the stable storage and the database is updated when a transaction commits.
  • Immediate database modification − Each log follows an actual database modification. That is, the database is modified immediately after every operation.

Recovery with Concurrent Transactions

When more than one transaction are being executed in parallel, the logs are interleaved. At the time of recovery, it would become hard for the recovery system to backtrack all logs, and then start recovering. To ease this situation, most modern DBMS use the concept of 'checkpoints'.

Checkpoint

Keeping and maintaining logs in real time and in real environment may fill out all the memory space available in the system. As time passes, the log file may grow too big to be handled at all. Checkpoint is a mechanism where all the previous logs are removed from the system and stored permanently in a storage disk. Checkpoint declares a point before which the DBMS was in consistent state, and all the transactions were committed.

Recovery

When a system with concurrent transactions crashes and recovers, it behaves in the following manner −
Recovery
  • The recovery system reads the logs backwards from the end to the last checkpoint.
  • It maintains two lists, an undo-list and a redo-list.
  • If the recovery system sees a log with <Tn, Start> and <Tn, Commit> or just <Tn, Commit>, it puts the transaction in the redo-list.
  • If the recovery system sees a log with <Tn, Start> but no commit or abort log found, it puts the transaction in undo-list.
All the transactions in the undo-list are then undone and their logs are removed. All the transactions in the redo-list and their previous logs are removed and then redone before saving their logs.

FUNCTIONAL DEPENDENCY

Q- WHAT IS FUNCTIONAL DEPENDENCY ?
ans-In relational database theory, a functional dependency is a constraint between two sets of attributes in a relation from a database.

Given a relation R, a set of attributes X in R is said to functionally determine another set of attributes Y, also in R, (written X → Y) if, and only if, each X value is associated with precisely one Yvalue; R is then said to satisfy the functional dependency X → Y. Equivalently, the projection \pi_{X,Y}R is a function, i.e. Y is a function of X.[1][2] In simple words, if the values for the X attributes are known (say they are x), then the values for the Y attributes corresponding to x can be determined by looking them up in any tuple of R containing x. Customarily X is called the determinant set and Y thedependent set. A functional dependency FD: X → Y is called trivial if Y is a subset of X.

Q what is armstrong AXIOMS?

Armstrong's Axioms

If F is a set of functional dependencies then the closure of F, denoted as F+, is the set of all functional dependencies logically implied by F. Armstrong's Axioms are a set of rules, that when applied repeatedly, generates a closure of functional dependencies.
  • Reflexive rule − If alpha is a set of attributes and beta is_subset_of alpha, then alpha holds beta.
  • Augmentation rule − If a → b holds and y is attribute set, then ay → by also holds. That is adding attributes in dependencies, does not change the basic dependencies.
  • Transitivity rule − Same as transitive rule in algebra, if a → b holds and b → c holds, then a → c also holds. a → b is called as a functionally that determines b.

Trivial Functional Dependency

  • Trivial − If a functional dependency (FD) X → Y holds, where Y is a subset of X, then it is called a trivial FD. Trivial FDs always hold.
  • Non-trivial − If an FD X → Y holds, where Y is not a subset of X, then it is called a non-trivial FD.
  • Completely non-trivial − If an FD X → Y holds, where x intersect Y = Φ, it is said to be a completely non-trivial FD.

Q-what is the need of normalization ?
 ans- normalization is used to   different   anomalies  in update, delete and insert operations soo 
normalization is used to remove those anomalies..


Q what is anomalies ?
Tables which meet the minimum requirement for a relation may not have an effective or appropriate structure. Changing the data in such tables can have undesirable consequences, called modification anomalies. 
Anomalies can be eliminated by redefining the relation into two or more relations. These redefined relations, or normalized, relations are preferred.

Q what  are different anomalies arises in the database design:?
 {  
ans-  there are mainly 3 types of anomalies in the database design .
  A- insertion anomalies 
     if  it is impossible to insert any data due to in sufficient details .  suppose in a school db enrollment of a student without class no is not possible and a student dont have class no  now ..
B- deletion anomalies -  this type of anomalie arises  when due to delete of  one tupple some  other data lost .. suppose an employee consist   a key no of its already covered project , now if  the details of that employee deleted than entire details of its covered project lost ..
C- update anomalies- update anomalies arises  a problem in the update process , ex-
  need to update same details at different  places...

}


Q what is a loss less join ?
ans-a decomposition  is said to be loss less if the we do natural join than data must remain same , 

Q what is dependency preservation ?

Dependency Preservation

  1. Another desirable property in database design is dependency preservation.
    • We would like to check easily that updates to the database do not result in illegal relations being created.
    • It would be nice if our design allowed us to check updates without having to compute natural joins.
    • To know whether joins must be computed, we need to determine what functional dependencies may be tested by checking each relation individually.
    • Let F be a set of functional dependencies on schema R.
    • Let tex2html_wrap_inline1550 be a decomposition of R.
    • The restriction of F to tex2html_wrap_inline1556 is the set of all functional dependencies in tex2html_wrap_inline1628 that include only attributes of tex2html_wrap_inline1556 .
    • Functional dependencies in a restriction can be tested in one relation, as they involve attributes in one relation schema.
    • The set of restrictions tex2html_wrap_inline1660 is the set of dependencies that can be checked efficiently.
    • We need to know whether testing only the restrictions is sufficient.
    • Let tex2html_wrap_inline1662 .
    • F' is a set of functional dependencies on schema R, but in general, tex2html_wrap_inline1668 .
    • However, it may be that tex2html_wrap_inline1670 .
    • If this is so, then every functional dependency in F is implied by F', and if F' is satisfied, then F must also be satisfied.
    • A decomposition having the property that tex2html_wrap_inline1670 is a dependency-preserving decomposition.

Normalization

If a database design is not perfect, it may contain anomalies, which are like a bad dream for any database administrator. Managing a database with anomalies is next to impossible.
  • Update anomalies − If data items are scattered and are not linked to each other properly, then it could lead to strange situations. For example, when we try to update one data item having its copies scattered over several places, a few instances get updated properly while a few others are left with old values. Such instances leave the database in an inconsistent state.
  • Deletion anomalies − We tried to delete a record, but parts of it was left undeleted because of unawareness, the data is also saved somewhere else.
  • Insert anomalies − We tried to insert data in a record that does not exist at all.
Normalization is a method to remove all these anomalies and bring the database to a consistent state.

First Normal Form

First Normal Form is defined in the definition of relations (tables) itself. This rule defines that all the attributes in a relation must have atomic domains. The values in an atomic domain are indivisible units.
unorganized relation
We re-arrange the relation (table) as below, to convert it to First Normal Form.
Relation in 1NF
Each attribute must contain only a single value from its pre-defined domain.

Second Normal Form

Before we learn about the second normal form, we need to understand the following −
  • Prime attribute − An attribute, which is a part of the prime-key, is known as a prime attribute.
  • Non-prime attribute − An attribute, which is not a part of the prime-key, is said to be a non-prime attribute.
If we follow second normal form, then every non-prime attribute should be fully functionally dependent on prime key attribute. That is, if X → A holds, then there should not be any proper subset Y of X, for which Y → A also holds true.
Relation not in 2NF
We see here in Student_Project relation that the prime key attributes are Stu_ID and Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name and Proj_Name must be dependent upon both and not on any of the prime key attribute individually. But we find that Stu_Name can be identified by Stu_ID and Proj_Name can be identified by Proj_ID independently. This is called partial dependency, which is not allowed in Second Normal Form.
Relation  in 2NF
We broke the relation in two as depicted in the above picture. So there exists no partial dependency.

Third Normal Form

For a relation to be in Third Normal Form, it must be in Second Normal form and the following must satisfy −
  • No non-prime attribute is transitively dependent on prime key attribute.
  • For any non-trivial functional dependency, X → A, then either −
      X is a superkey or,
    • A is prime attribute.
Relation not in 3NF
We find that in the above Student_detail relation, Stu_ID is the key and only prime key attribute. We find that City can be identified by Stu_ID as well as Zip itself. Neither Zip is a superkey nor is City a prime attribute. Additionally, Stu_ID → Zip → City, so there existstransitive dependency.
To bring this relation into third normal form, we break the relation into two relations as follows −
Relation in 3NF

Boyce-Codd Normal Form

Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict terms. BCNF states that −
  • For any non-trivial functional dependency, X → A, X must be a super-key.
In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key in the relation ZipCodes. So,
Stu_ID → Stu_Name, Zip
and
Zip → City
Which confirms that both the relations are in BCNF.