l-5 normaalization & sql

10
L-20: DBMS: Normalization - Normalized File Layout Flat File/ Unstructured data file – Flat File/ Unstructured data file – PROBLEMS PROBLEMS More than one value per cell makes simple More than one value per cell makes simple manipulation impossible manipulation impossible Update/delete/modify anomalies will occur Update/delete/modify anomalies will occur Redundant information exists Redundant information exists Normalization – Normalization – It is the process of simplifying data structure by It is the process of simplifying data structure by replacing it with smaller and multiple data replacing it with smaller and multiple data structure structure which will have integrity and which will have integrity and consistency . consistency . Normalized data characteristics – Normalized data characteristics – Reduces data redundancy. Reduces data redundancy. Avoids Update/delete/modify anomalies. Avoids Update/delete/modify anomalies. Reduces inconsistent data. Reduces inconsistent data. Easy to maintain Easy to maintain

Upload: ramanand

Post on 19-Nov-2015

217 views

Category:

Documents


2 download

DESCRIPTION

ss

TRANSCRIPT

  • L-20: DBMS: Normalization - Normalized File Layout Flat File/ Unstructured data file PROBLEMS More than one value per cell makes simple manipulation impossibleUpdate/delete/modify anomalies will occurRedundant information existsNormalization It is the process of simplifying data structure by replacing it with smaller and multiple data structure which will have integrity and consistency .Normalized data characteristics Reduces data redundancy.Avoids Update/delete/modify anomalies.Reduces inconsistent data. Easy to maintain

  • L-20: DBMS: Normalization - Normalized File Layout Normalization

    1NF: No duplicate rows, Each cell contains single value,

    Column entries are of same kind.(i.e. each attribute consist of single fact about an entity)

    2NF: table is in 1NF and contains no partial dependencies; (i.e. each non-key attribute is dependent on whole/entire primary key)

    3NF: table is in 2NF and contains no transitive dependencies i.e. (i.e no non-key attributes dependent on other non-key attributes)

  • L-20: DBMS: Normalization - Normalized File Layout - example Flat File - No keys, Repetitive values in a cell Software companys data base

    Project Number Project Name Employee Number Employee Name Rate category Hourly Rates 1023Mod Travels 111216VincentPaulCharlesABC$60$50$401056Star Residency1117VincentWilliamsAB$60$50

  • L-20: DBMS: Normalization - Normalized File Layout - example 1NF Key is present and each cell contains single value But note Project name dependent on Project Number and Employee name on Employee Number ( Every non key column is not dependent on full primary key but a part of PK suffice the purpose)

    Project Number # Project Name Employee Number # Employee Name Rate category Hourly Rates 1023Mod Travel Site11VincentA$601023Mod Travel Site12PaulB$501023Mod Travel Site16CharlesC$401056Star Residency11VincentA$601056Star Residency17WilliamsB$50

  • L-20: DBMS: Normalization - Normalized File Layout - example 2 NF Every column is now dependent on same keyEmployee table Project tableEmployee_Project table

    Emp_No # Emp_ Name Rate category Hourly Rates 11VincentA$6012PaulB$5016CharlesC$4011VincentA$6017WilliamsB$50

    Prj_No # Project Name 1023Mod Travel Site1056Star Residency

    Prj_No #Emp_No #102311102312102316105611105617

  • L-20: DBMS: Normalization - Normalized File Layout - example 2 NF Every column is now dependent on same keyEmployee table BUT Note the transitive dependency - Hourly Rates depends on Rate Category and Rate Category depends on Employee .

    Emp_No # Emp_ Name Rate category Hourly Rates 11VincentA$6012PaulB$5016CharlesC$4011VincentA$6017WilliamsB$50

  • L-20: DBMS: Normalization - Normalized File Layout - example 3 NF Remove the transitive dependency by further splitting the table as belowEmployee table Rate table

    Emp_No # Emp_ Name Rate category 11VincentA12PaulB16CharlesC17WilliamsB

    Rate category Hourly rateA$60B$50C$40

  • L-20: DBMS: Tips & Tricks of File Layout Confused of these technicalities??? then just remember following tricks Keep your table layouts small and simple Incorporate required and relevant attributes/columns of an entity in your table Avoid the repetition of columns in your tables Invariably define/mark key column Ensure that all columns are identifiable by so defined key

  • L-20: DBMS: SQL - SQL CREATE TABLE STATION (ID INTEGER PRIMARY KEY, CITY CHAR(20), STATE CHAR(2), LAT_N REAL, LONG_W REAL);

    INSERT INTO STATION VALUES (13, 'Phoenix', 'AZ', 33, 112); INSERT INTO STATION VALUES (44, 'Denver', 'CO', 40, 105);

    SELECT * FROM STATION

    SELECT * FROM STATION WHERE LAT_N > 39.7;

    SELECT ID, CITY, STATE FROM STATION;

    SELECT ID, CITY, STATE FROM STATION WHERE LAT_N > 39.7

  • L-20: DBMS: SQL - SQL SELECTCID, Name, Phone, City, AccountBalanceFROMCustomersWHEREAccountBalance > 200 ;

    SELECTCID, City, AccountBalancelFROMCustomersWHEREAccountBalance > 200 and City = DenverORDER BY Name ASC ;

    SELECT EmployeeTable.EmpNo, EmployeeTable.EmpLastName WHERE LastName = Quint

    SELECT MONTH, ID, RAIN_I, TEMP_F FROM STATS ORDER BY MONTH, RAIN_I DESC;

    SELECT LAT_N, CITY, TEMP_F FROM STATS, STATION WHERE MONTH = 7 AND STATS.ID = STATION.ID ORDER BY TEMP_F;