Sunteți pe pagina 1din 4

Ex.no:10 NORMALISATION Aim: To create and access database normalization without data redundancy.

Description: ER-model: It allows entity sets and relationship sets to have attributes that have same degree to have substructure.Specifically it allows multi valued attributes and composite attributes. Normalisation: Normalisation is used to minimize data redundancy 1NF: A relation is in first normal form if all its attributes are simple or atomic.None of its relation is again a relation. 2NF:A first normal form relation is in second normal form if all its non-primary attributes are fully functionally dependent on the primary key. It eliminates partial dependency. 3NF:A second normal form relation is in third normal form if all non-primary attributes have non-transitivity dependency on primary key.It eliminates transitivity OUTPUT: SQL>create table dept0(deptname varchar(10),deptid number(7),plvis varchar(30)); Table created. SQL>create table dept1(deptname varchar(7),deptid number(7),p1 varhcar(7),p2 varchar(7),p3 varchar(7)); Table created. SQL>create table dept2(deptname varchar(10),deptid number(7),p1 varchar(7)); Table created. SQL> insert into dept0 values('cse',10,'erode,salem,kovai'); 1 row created.

SQL> declare cursor c is select * from dept0; 2 r1 dept0 % rowtype; 3 r2 dept0 % rowtype; 4 p1 dept0.plvis % type; 5 p2 dept0.plvis % type; 6 p3 dept0.plvis % type; 7 s1 number(3);

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

s2 number(3); s3 number(3); i number(3); len number(3); ch varchar(1); begin dbms_output.put_line('Normalised table without duplication'); dbms_output.put_line('deptname'||' '||'deptid'||' '||'plvi1'||' '||'plvi2'||' '||'plvi3'); for r1 in c loop i:=1; s1:=0; s2:=0; s3:=0; len:=length(r1.plvis); if substr(r1.plvis,len,1)<>'.'then r1.plvis:=r1.plvis||'.'; end if; while len>=0 loop ch:=substr(r1.plvis,i,1); if ch=',' or ch='.' then if s1=0 then s1:=i; else if s2=0 then s2:=i; else if s3=0 then s3:=i; end if; end if; end if; end if; len:=len-1; i:=i+1; end loop; p1:=substr(r1.plvis,1,s1-1); p2:=substr(r1.plvis,s1+1,s2-1-s1); p3:=substr(r1.plvis,s2+1,s3-1-s2); dbms_output.put_line(r1.deptname||' '||r1.deptid||' '||p1||' '||p2||' '||p3); insert into dept1 values(r1.deptname,r1.deptid,p1,p2,p3); end loop; dbms_output.put_line('Normalised table with duplication'); dbms_output.put_line('deptname'||' '||'deptid'||' '||'plvis'); for r2 in c loop i:=1; s1:=0;

54 s2:=0; 55 s3:=0; 56 len:=length(r2.plvis); 57 if substr(r2.plvis,len,1)<>'.'then 58 r2.plvis:=r2.plvis||'.'; 59 end if; 60 while len>=0 loop 61 ch:=substr(r2.plvis,i,1); 62 if ch=',' or ch='.'then 63 if s1=0 then 64 s1:=i; 65 else if s2=0 then 66 s2:=i; 67 else if s3=0 then 68 s3:=i; 69 end if; 70 end if; 71 end if; 72 end if; 73 len:=len-1; 74 i:=i+1; 75 end loop; 76 p1:=substr(r2.plvis,1,s1-1); 77 p2:=substr(r2.plvis,s1+1,s2-1-s1); 78 p3:=substr(r2.plvis,s2+1,s3-1-s2); 79 dbms_output.put_line(r2.deptname||' '||r2.deptid||' '||p1); 80 insert into dept2 values(r2.deptname,r2.deptid,p1); 81 if s2<>0 then 82 dbms_output.put_line(r2.deptname||' '||r2.deptid||' '||p2); 83 insert into dept2 values(r2.deptname,r2.deptid,p2); 84 end if; 85 if s3<>0 then 86 dbms_output.put_line(r2.deptname||' '||r2.deptid||' '||p3); 87 insert into dept2 values(r2.deptname,r2.deptid,p3); 88 end if; 89 end loop; 90 end; 91 / Normalised table without duplication deptname deptid plvi1 plvi2 plvi3 cse 10 erode salem kovai Normalised table with duplication deptname deptid plvis cse 10 erode cse 10 salem cse 10 kovai

PL/SQL procedure successfully completed.

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