You are on page 1of 15

Advances in Database Management Systems

(10SCS13)

Advances in Database Management Systems Lab Experiments
1. Develop a database application to demonstrate storing and retrieving of BLOB and CLOB objects. 2. Develop a database application to demonstrate the representation of multivalued attributes, and use of nested tables to represent complex objects. Write suitable queries to demonstrate it. 3. Design and develop a suitable Student Database application. One of the attributes to me maintained is the attendance of a student in each subject for which he/she has enrolled. Using TRIGGERS, we write active rules to do the following: A. Whenever attendance is updated, check if the attendance is less than 85%; if so notify the Head of Department concerned. B. Whenever the marks in the Internal Assessment Test are entered, check if the marks are less than 40%; if so, notify the Head of the Department concerned. 4. Design, develop and execute a program in a language of your choice to implement any one algorithm for mining association rules. Run the program against any large database available in the public domain and discuss the results.

I Sem. M.Tech. CSE (QIP) 2011-12

Page 1 of 15

con). SqlCommandBuilder cmb = new SqlCommandBuilder(adapter). FileAccess.Text.Data. String curFilename. String connectionString = id=sa.Windows. textBox3. String sql = "SELECT * FROM EMPLOYEES". SqlDataAdapter adapter = new SqlDataAdapter(sql.Text. using System. using System.Open(). row["ename"] = textBox2.Text != "") { FileStream file = new FileStream(curFilename. adapter.Advances in Database Management Systems (10SCS13) Experiment 1 1) Develop a database application to demonstrate storing and retrieving of BLOB and CLOB objects. con.user private void button1_Click(object sender.Data. } } private void button2_Click(object sender.OpenOrCreate. "EMPLOYEES").Tech. CSE (QIP) 2011-12 Page 2 of 15 . byte[] rawdata = new byte[file. using System. } "server=localhost.Read(rawdata.Forms.password=password".Convert.Drawing. using System. EventArgs e) { if (textBox3.Collections. FileMode.Tables["EMPLOYEES"].database=college.OK) { curFilename = openDlg. M. String savedImageName = "".SqlClient. SOURCE CODE using System.Length)). row["photo"] = rawdata. con. public Form1() { InitializeComponent(). DataSet ds = new DataSet("EMPLOYEES"). EventArgs e) { OpenFileDialog openDlg = new OpenFileDialog().IO. using System. DataRow row = ds.NewRow().Text. SqlConnection con = new SqlConnection().FileName. I Sem. using System.Text = curFilename.ToInt32(file.Fill(ds. if (openDlg. using System.Close(). System. 0.ShowDialog() == DialogResult. using System. file.Read).ConnectionString = connectionString.ComponentModel. file.Length]. namespace BLOB { public partial class Form1 : Form { Image curImage.Generic. row["empcode"] = textBox1.

con.Text. curImage = Image. bw. 0.Close(). SqlDataReader myReader = command.ExecuteReader(CommandBehavior. bw.Advances in Database Management Systems ds.Read()) { file = new FileStream(savedImageName.Tech. con. outbyte. buffersize). outbyte.GetBytes(2.Update(ds.Close(). file. 0. FileMode.Invalidate().Write ). startindex += buffersize. M. startindex. MessageBox. startindex = 0.Flush().1). } } (10SCS13) private void button3_Click(object sender. } } } } I Sem. pictureBox1. 0. long startindex = 0.OpenOrCreate.Close().Write(outbyte. bw = new BinaryWriter(file). CSE (QIP) 2011-12 Page 3 of 15 . SqlCommand command = new SqlCommand(sql. while (retval == buffersize) { bw. adapter.Image = curImage. EventArgs e) { if (textBox1.Close(). startindex. con. int buffersize = 100. retval = myReader. (int)retval . "EMPLOYEES").Add(row).Rows. } con.Tables["EMPLOYEES"].ConnectionString = connectionString.Close(). byte[] outbyte = new byte[buffersize]. savedImageName = textBox3. BinaryWriter bw. con. pictureBox1.Write(outbyte).SequentialAccess).Flush(). FileStream file. bw.Show("Image Saved").GetBytes(2.Open().FromFile(savedImageName). con). retval = myReader. buffersize). SqlConnection con = new SqlConnection(). } bw. while (myReader. long retval.Text. FileAccess.Text != "") { String sql = "Select * from employees where empcode=" + textBox1.

M.Tech. CSE (QIP) 2011-12 Page 4 of 15 .Advances in Database Management Systems OUTPUT (10SCS13) I Sem.

M. and use of nested tables to represent complex objects. SQL> CREATE TYPE t_experience AS OBJECT 2 ( 3 CompanyName varchar2(20). Write suitable queries to demonstrate it.Advances in Database Management Systems (10SCS13) Experiment 2 2) Develop a database application to demonstrate the representation of multivalued attributes.'l'. 1 row created. Table created. Type created. Type created.3). 1 row created.3) 5 ) 6 ). 4 t_experience('git'.'ai'. t_experience_tbl 3 ( t_experience('git'.'Research fellow'. SQL> CREATE TABLE employees 2 ( Name varchar2(20). SQL> insert into employees values 2 ( 'jag'.Tech. 4 t_experience('xyz company'. 5 t_experience('mnp company'. 3 Experiences t_experience_tbl) 4 NESTED TABLE Experiences STORE AS Experiences_tab.'Software Engineer'. 5 NoOfYears number(2) 6 ). I Sem. SQL> insert into employees values 2 ( 'gaj'. t_experience_tbl 3 ( t_experience('abc company'.'System Analyst'. 4 Position varchar2(20). SQL> CREATE TYPE t_experience_tbl AS TABLE OF t_experience.4) 6 ) 7 ).1). CSE (QIP) 2011-12 Page 5 of 15 .2).

a.---------abc company 3 xyz company 2 mnp company 4 SQL> select a.CompanyName. T_EXPERIENCE('git'. POSITION. M.NoOfYears from 2 table(select experiences from employees where name='jag') a. 3). 4)) gaj T_EXPERIENCE_TBL(T_EXPERIENCE('git'. CSE (QIP) 2011-12 Page 6 of 15 .Tech. T_EXPERIENCE('mnp company'.Advances in Database Management Systems OUTPUT: SQL> select * from employees. 'Software Engineer'. 'ai'.NoOfYears from 2 the(select experiences from employees where name='gaj') a. 'Research fe llow'.CompanyName. 1). NOOFYEARS) -------------------------------------------------------------------------------jag T_EXPERIENCE_TBL(T_EXPERIENCE('abc company'. 'l'. 'System Analyst'. T_EXPERIEN CE('xyz company'. (10SCS13) NAME -------------------EXPERIENCES(COMPANYNAME. COMPANYNAME NOOFYEARS -------------------. 3)) SQL> select a.a. COMPANYNAME NOOFYEARS -------------------. 2).---------git 1 git 3 I Sem.

check if the attendance is less than 85%. 5 m3 integer. 3 m1 integer. 6 m4 integer. M. 7 m5 integer. SQL> select * from marks. notify the Head of the Department concered. SQL> insert into marks values('2gi05cs002'.Tech.---------.---------. we write active rules to do the following: A.---------. USN M1 M2 M3 M4 M5 M6 ---------.11.10.10. 11. Whenever the marks in the Internal Assessment Test are entered. B. SQL> insert into marks values('2gi05cs012'.10.11. 10. 8 m6 integer). SQL> insert into marks values('2gi05cs018'.10.11). 1 row created. 1 row created.11). CSE (QIP) 2011-12 Page 7 of 15 .17.10). 1 row created.11. 4 m2 integer.11. check if the marks are less than 40%. 20.Advances in Database Management Systems (10SCS13) Experiment 3 3) Design and develop a suitable Student Database application. Table created.11. if so. Using TRIGGERS. Whenever attendance is updated. I Sem. PART A: SQL> create table marks( 2 usn varchar2(10) primary key.---------.---------.18.---------2gi05cs012 10 10 10 10 10 10 2gi05cs002 11 11 11 11 11 11 2gi05cs018 20 11 18 17 10 11 SQL> create or replace trigger mtrigger 2 after insert or update on marks 3 for each row 4 declare 5 marks_exception1 exception.10. if so notify the Head of Department concerned. One of the attributes to me maintained is the attendance of a student in each subject for which he/she has enrolled.

40 end.99). 14 if :new. (10SCS13) OUTPUT (PART A): SQL> insert into marks values('2gi05cs020'. 30 when marks_exception2 then 31 raise_application_error(-20002. 7 marks_exception3 exception.m2/maximum_marks*100<40 then 17 raise marks_exception2. CSE (QIP) 2011-12 Page 8 of 15 . line 26 ORA-04088: error during execution of trigger 'MTECH. 8 marks_exception4 exception.60. 24 elsif :new.88. 18 elsif :new. 36 when marks_exception5 then 37 raise_application_error(-20005.m4/maximum_marks*100<40 then 21 raise marks_exception4. 34 when marks_exception4 then 35 raise_application_error(-20004. 12 begin 13 maximum_marks:=&maximum_marks. 11 maximum_marks integer. 26 end if.20.'Marks less than 40% in M1'). 9 marks_exception5 exception.55.60.'Marks less than 40% in M5').55. 41 / Enter value for maximum_marks: 100 old 13: maximum_marks:=&maximum_marks. 27 exception 28 when marks_exception1 then 29 raise_application_error(-20001.77.20. 32 when marks_exception3 then 33 raise_application_error(-20003. M.77. 38 when marks_exception6 then 39 raise_application_error(-20006.'Marks less than 40% in M2'). Trigger created.Advances in Database Management Systems 6 marks_exception2 exception. insert into marks values('2gi05cs020'.'Marks less than 40% in M4'). 22 elsif :new.m3/maximum_marks*100<40 then 19 raise marks_exception3. 10 marks_exception6 exception.MTRIGGER' I Sem.'Marks less than 40% in M3').'Marks less than 40% in M6'). 20 elsif :new. new 13: maximum_marks:=100.99) * ERROR at line 1: ORA-20001: Marks less than 40% in M1 ORA-06512: at "MTECH.MTRIGGER".m5/maximum_marks*100<40 then 23 raise marks_exception5. 16 elsif :new.m6/maximum_marks*100<40 then 25 raise marks_exception6.m1/maximum_marks*100<40 then 15 raise marks_exception1.88.Tech.

---------. Table created.11.10. SQL> insert into attendance values('2gi05cs003'. 1 row created.8. 10. SQL> select * from attendance.55. 1 row created.10.88.MTRIGGER". M.---------.---------2gi05cs001 10 10 10 10 10 10 2gi05cs002 11 11 11 11 11 11 2gi05cs003 10 11 8 7 10 11 SQL> create or replace trigger atrigger 2 after update on attendance 3 for each row 4 declare I Sem.10).60.11. 5 att3 integer.10.11).11). 10. SQL> insert into attendance values('2gi05cs001'. USN ATT1 ATT2 ATT3 ATT4 ATT5 ---------.7.---------.10.40.---------. 11. 4 att2 integer.---------.Tech.MTRIGGER' (10SCS13) PART B: SQL> create table attendance( 2 usn varchar2(10) primary key.11.99). CSE (QIP) 2011-12 Page 9 of 15 ATT6 . 3 att1 integer.11. SQL> update marks 2 set m2=8 3 where usn='2gi05cs012'. 1 row created. SQL> insert into attendance values('2gi05cs002'. 8 att6 integer). update marks * ERROR at line 1: ORA-20001: Marks less than 40% in M1 ORA-06512: at "MTECH. line 26 ORA-04088: error during execution of trigger 'MTECH. 6 att4 integer. 1 row created.77.11. 7 att5 integer.Advances in Database Management Systems SQL> insert into marks values('2gi05cs020'.10.

'Attendance less than 85% in Subject 5'). when attn_exception4 then raise_application_error(-20004.'Attendance less than 85% in Subject 4'). elsif :new. when attn_exception5 then raise_application_error(-20005. elsif :new. M. if :new. elsif :new. attn_exception4 exception. CSE (QIP) 2011-12 Page 10 of 15 . I Sem. when attn_exception2 then raise_application_error(-20002. attn_exception5 exception. end if. when attn_exception6 then raise_application_error(-20006. Enter value for total_classes: 50 old 13: total_classes:=&total_classes.att3/total_classes*100<85 then raise attn_exception3.Tech.att2/total_classes*100<85 then raise attn_exception2. exception when attn_exception1 then raise_application_error(-20001.att5/total_classes*100<85 then raise attn_exception5.att6/total_classes*100<85 then raise attn_exception6. elsif :new. end.'Attendance less than 85% in Subject 3'). new 13: total_classes:=50. total_classes integer. elsif :new. attn_exception3 exception.'Attendance less than 85% in Subject 6').'Attendance less than 85% in Subject 1'). begin total_classes:=&total_classes. attn_exception6 exception.att1/total_classes*100<85 then raise attn_exception1. when attn_exception3 then raise_application_error(-20003. attn_exception2 exception. Trigger created.att4/total_classes*100<85 then raise attn_exception4.'Attendance less than 85% in Subject 2').Advances in Database Management Systems 5 6 7 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 (10SCS13) attn_exception1 exception.

CSE (QIP) 2011-12 Page 11 of 15 .ATT4=48.ATT6=47 3 WHERE USN='2tg04is051'.Tech.Advances in Database Management Systems OUTPUT (PART B): SQL> UPDATE ATTENDANCE 2 SET ATT1=5 3 WHERE USN='2tg04is051'.ATT3=47. (10SCS13) I Sem. line 26 ORA-04088: error during execution of trigger 'MTECH.ATT2=45. UPDATE ATTENDANCE * ERROR at line 1: ORA-20001: Attendance less than 85% in Subject 1 ORA-06512: at "MTECH. 1 row updated. M.ATT5=49.ATRIGGER".ATRIGGER' SQL> UPDATE ATTENDANCE 2 SET ATT1=46.

Add(strGeneratedCandidate.1]. } private string GetCandidate(string strFirstItem. dSupport). strSecondItem).1). } else return string. } else { string strFirstSubString = strFirstItem.Substring(0. M. } } } return dic_CandidatesReturn. double>().ElementAt(i)). double> GenerateCandidates(Dictionary<string.ElementAt(j)).Length. if (strFirstSubString == strSecondSubString) { return strFirstItem + strSecondItem[nLength . i++) { string strFirstItem = Alphabetize(dic_FrequentItems. if (nLength == 1) { return strFirstItem + strSecondItem. j++) { string strSecondItem = Alphabetize(dic_FrequentItems. i < dic_FrequentItems.Substring(0. dic_CandidatesReturn. double dSupport = GetSupport(strGeneratedCandidate). string strSecondItem) { int nLength = strFirstItem. } } I Sem. string strGeneratedCandidate = GetCandidate(strFirstItem.Keys. Run the program against any large database available in the public domain and discuss the results.1.Empty. nLength . for (int j = i + 1. j < dic_FrequentItems. Tricky Part 1: Generating Candidates Collapse private Dictionary<string.Advances in Database Management Systems (10SCS13) Experiment 4 3) Design. develop and execute a program in a language of your choice to implement any one algorithm for mining association rules.Keys.Count . double> dic_CandidatesReturn = new Dictionary<string. if (strGeneratedCandidate != string. string strSecondSubString = strSecondItem. CSE (QIP) 2011-12 Page 12 of 15 . for (int i = 0. nLength 1).Empty) { strGeneratedCandidate = Alphabetize(strGeneratedCandidate).Tech.Count. double> dic_FrequentItems) { Dictionary<string.

M.ToString(). strItem. strItem. double> dic_FrequentItems = dic_FrequentItemsL1. ////Scan the transaction database to get the support S of each 1-itemset. Dictionary<string. double dMinConfidence = double. Dictionary<string.Text) / 100. int nCombinationLength. ref lstRulesReturn). ref lstRulesReturn). double> dic_FrequentItemsL1 = GetL1FrequentItems(dMinSupport). } return. return. ref lstRulesReturn).Text) / 100.ToString(). } else { for (int i = 0. } else if (nItemLength == 3) { for (int i = 0. Dictionary<string. ref lstRulesReturn).Length.ToString(). double> dic_Candidates = new Dictionary<string.Tech. } } return lstRulesReturn. double>(). foreach (string strItem in m_dicAllFrequentItems.Advances in Database Management Systems Tricky Part 2: Generating Rules Collapse (10SCS13) private List<clssRules> GenerateRules() { List<clssRules> lstRulesReturn = new List<clssRules>(). CSE (QIP) 2011-12 Page 13 of 15 . nCombinationLength. i++) { GetCombinationRecursive(strItem[i]. I Sem.Length / 2.Parse(txt_Support.Parse(txt_Confidence. i < nItemLength. } private void GenerateCombination(string strItem. GenerateCombination(strItem. } } } private void Solve() { double dMinSupport = double. strItem.Length > 1) { int nMaxCombinationLength = strItem.Keys) { if (strItem. if (nItemLength == 2) { AddItem(strItem[0]. i++) { AddItem(strItem[i]. ref List<clssRules> lstRulesReturn) { int nItemLength = strItem. i < nItemLength. nMaxCombinationLength.

ShowDialog(). lstStrongRules). dicClosedItemSets.Advances in Database Management Systems do { (10SCS13) dMinSupport).Count != 0). objfrmOutput. lstRules). CSE (QIP) 2011-12 Page 14 of 15 . double>> dicClosedItemSets = GetClosedItemSets(). Dictionary<string. } while (dic_Candidates. List<clssRules> lstStrongRules = GetStrongRules(dMinConfidence. M. List<clssRules> lstRules = GenerateRules().Tech. dic_FrequentItems = GetFrequentItems(dic_Candidates. } I Sem. dic_Candidates = GenerateCandidates(dic_FrequentItems). lstMaximalItemSets. frmOutput objfrmOutput = new frmOutput(m_dicAllFrequentItems. Dictionary<string. List<string> lstMaximalItemSets = GetMaximalItemSets(dicClosedItemSets).

Tech.Advances in Database Management Systems OUTPUT (PART B): (10SCS13) I Sem. M. CSE (QIP) 2011-12 Page 15 of 15 .