







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








First normal form (1NF) As per the rule of first normal form, an attribute (column) of a table cannot hold multiple values. It should hold only atomic values. Example : Suppose a company wants to store the names and contact details of its employees. It creates a table that looks like this:
emp_id emp_name emp_address emp_mobile 101 Herschel New Delhi 8912312390 102 Jon Kanpur 8812121212 9900012222 103 Ron Chennai 7778881212 104 Lester Bangalore 9990000123 8123450987 Two employees (Jon & Lester) are having two mobile numbers so the company stored them in the same field as you can see in the table above. This table is not in 1NF as the rule says “each attribute of a table must have atomic (single) values”, the emp_mobile values for employees Jon & Lester violates that rule. To make the table complies with 1NF we should have the data like this:
teacher_id subject teacher_age 111 Maths 38 111 Physics 38 222 Biology 38 333 Physics 40 333 Chemistry 40 Candidate Keys : {teacher_id, subject} Non prime attribute : teacher_age The table is in 1 NF because each attribute has atomic values. However, it is not in 2NF because non prime attribute teacher_age is dependent on teacher_id alone which is a proper subset of candidate key. This violates the rule for 2NF as the rule says “ no non- prime attribute is dependent on the proper subset of any candidate key of the table”. To make the table complies with 2NF we can break it in two tables like this: teacher_details table:
teacher_id teacher_age 111 38 222 38 333 40 teacher_subject table: teacher_id subject 111 Maths 111 Physics 222 Biology 333 Physics
emp_id emp_name emp_zip emp_state emp_city emp_district 1001 John 282005 UP Agra Dayal Bagh 1002 Ajeet 222008 TN Chennai M-City 1006 Lora 282007 TN Chennai Urrapakkam 1101 Lilly 292008 UK Pauri Bhagwan 1201 Steve 222999 MP Gwalior Ratan Super keys : {emp_id}, {emp_id, emp_name}, {emp_id, emp_name, emp_zip}…so on Candidate Keys : {emp_id} Non-prime attributes : all attributes except emp_id are non-prime as they are not part of any candidate keys. Here, emp_state, emp_city & emp_district dependent on emp_zip. And, emp_zip is dependent on emp_id that makes non-prime attributes (emp_state, emp_city & emp_district) transitively dependent on super key (emp_id). This violates the rule of 3NF. To make this table complies with 3NF we have to break the table into two tables to remove the transitive dependency: employee table:
emp_id emp_name emp_zip 1001 John 282005 1002 Ajeet 222008 1006 Lora 282007 1101 Lilly 292008 1201 Steve 222999 employee_zip table:
It occurs when B is a subset of A in − Example We are considering the same
It occurs when B is not a subset of A in − Example The above is a non-trivial functional dependency since DeptName is a not a subset of DeptId.
It occurs when A intersection B is null in −
{ DeptId, DeptName } - > Dept Id A - >B DeptId - > DeptName A - >B
An aggregate function allows you to perform a calculation on a set of values to return a single scalar value. We often use aggregate functions with the GROUP BYand HAVING clauses of the SELECT statement. The following are the most commonly used SQL aggregate functions: AVG- calculates the average of a set of values. Eg SELECT AVG(unitsinstock) FROM Products COUNT– counts rows in a specified table or view. Eg SELECT COUNT(*) FROM Products MIN– gets the minimum value in a set of values. Eg SELECT MIN(unitsinstock) FROM products; MAX– gets the maximum value in a set of values. Eg SELECT
GRANT - gives user’s access privileges to database. REVOKE - withdraw user’s access privileges given by using the GRANT command.