C Program to Check BCNF,3NF
This is the C Program to check BCNF or 3NF
The difference between 3NF and BCNF is subtle.
3NF
Definition
A relation is in 3NF if it is in 2NF and no non-prime attribute transitively depends on the primary key. In other words, a relation R is in 3NF if for each functional dependency X ⟶ A in R at least one of the following conditions are met:
X is a key or superkey in R
A is a prime attribute in R
Example
Given the following relation:
EMP_DEPT(firstName, employeeNumber, dateOfBirth, address, departmentNumber, departmentName)
An employee can only work in one department and each department has many employees.
The candidate key is employeeNumber.
Consider the following functional dependencies:
employeeNumber ⟶ firstName, dateOfBirth, address, departmentNumber
departmentNumber ⟶ departmentName
Given the definition above it is possible to conclude that the relation EMP_DEPT is not in 3NF because the second functional dependency does not meet any of the 2 conditions of the 3NF:
departmentNumber is not a key or superkey in EMP_DEPT
departmentName is not a prime attribute in EMP_DEPT
BCNF
Definition
A relation R is in BCNF if it is in 3NF and for each functional dependency X ⟶ A in R, X is a key or superkey in R. In other words, the only difference between 3NF and BCNF is that in BCNF it is not present the second condition of the 3NF. This makes BCNF stricter than 3NF as any relation that is in BCNF will be in 3NF but not necessarily every relation that is in 3NF will be in BCNF.
Example
Given the following relation:
STUDENT_COURSE(studentNumber, socialSecurityNumber, courseNumber)
A student can assist to many courses and in a course there can be many students.
The candidate keys are:
socialSecurityNumber, courseNumber
studentNumber, courseNumber
Consider the following functional dependencies:
studentNumber ⟶ socialSecurityNumber
socialSecurityNumber ⟶ studentNumber
Given the definitioin above it is possible to conclude that STUDENT_COURSE is not in BCNF as at least studentNumber is not a key or superkey in STUDENT_COURSE
#include<stdio.h>
#include<string.h>
main()
{
char attr[20],fds[10][20],key[20],left[20],right[20];
int nooffds,noofattr,bcnf=1,tnf=1,found=0,i,j,k;
printf("Enter the number of attributesn");
scanf("%d",&noofattr);
for(i=0;i<noofattr;i++) {attr[i]='A'+i;printf("%c",attr[i]);if(i!=noofattr-1) printf(",");}
printf("n");
printf("Enter the keyn");
scanf("%s",key);
trim(key);strdup(key);
printf("Enter the number of fdsn");
scanf("%d",&nooffds);
for(i=0;i<nooffds;i++)
{
scanf("%s",fds[i]);
trim(fds[i]);
strdup(fds[i]);
}
for(i=0;i<nooffds;i++)
{
for(k=0,found=0,j=0;j<strlen(fds[i]);j++)
{
if(fds[i][j]=='-') {
left[k]='