Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul

Similar presentations


Presentation on theme: "Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul"— Presentation transcript:

1 Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul Kwanchai@rmutl.ac.th

2 Contents Week-5 XML Basics 5: 7 ธค. – DOM – XML DTD – XML Schema XML Query – Xpath 6: 14 ธค – Xquery7: 21 ธค – XSL 8: 24 ธค WebService 9: 4 มค – TH-E-GIF DataIntegration 10: 11 มค – Schema matching and mapping Parallel Database 11:18 มค GIS 12:

3 Contents Week-5 XML Basics 5: 7 ธค. – DOM – XML DTD – XML Schema : 14 ธค XML Query – Xpath 6: 21 ธค – Xquery7: 24 ธค – XSL 8: 24 ธค WebService 9: 4 มค – TH-E-GIF DataIntegration 10: 11 มค – Schema matching and mapping Parallel Database 11:18 มค GIS 12:

4 XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

5 Week5-Lab Construct and Validate your XML document using DTD and php.

6 XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

7 XML Document example

8 8 From Stanford: Well-Formed and Valid XML Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

9 9 From Stanford: Well-Formed and Valid XML Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

10 10 What are XML syntax rules? Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. What is “Well-Formed XML ”?

11 11 What are XML syntax rules? 1.? 2.? 3.? 4.? 5.?

12 12 What are XML syntax rules?

13 13 From Stanford: Well-Formed XML Start the document with a declaration, surrounded by. Normal declaration is: – “standalone” = “no DTD provided.” Balance of document is a root tag surrounding nested tags.

14 XML DTD

15

16

17

18 DTD Declaration

19 GUESS??? Internal or External???

20 DTD Declaration GUEST??? Internal or External???

21 DTD Declaration GUEST??? Internal or External???

22 DTD Declaration External Declaration note.dtd

23 Internal DTD Declaration

24 24 Refresh From Stanford: Well-Formed XML Start the document with a declaration, surrounded by. Normal declaration is: – “standalone” = “no DTD provided.” Balance of document is a root tag surrounding nested tags.

25 25 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.? 2.?

26 26 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 2.?

27 27 From Wiki: Example 1.? 2.? 3.? 4.?

28 28 From Wiki: Example 2.? 3.? 4.?

29 29 From Wiki: Example 3.? 4.?

30 30 From Wiki: Example 4.?

31 31 From Wiki: Example

32 DTD Declaration Exercise External Declaration note.dtd

33 33 From Stanford: Example: (b) Assume the BARS DTD is in file bar.dtd. Joe’s Bar Bud 2.50 Miller 3.00 … Get the DTD from the file bar.dtd 1.? External Declaration

34 34 From Stanford: Example: (b) Assume the BARS DTD is in file bar.dtd. Joe’s Bar Bud 2.50 Miller 3.00 … Get the DTD from the file bar.dtd External Declaration

35 35 From Wiki: Example 1.? 2.? 3.? External Declaration

36 36 From Wiki: Example 2.? 3.? External Declaration

37 37 From Wiki: Example 3.? External Declaration

38 38 From Wiki: Example

39 Why using DTD

40

41 DTD - XML Building Blocks

42 DTD - Elements

43 DTD - Attributes

44 DTD - Entities

45 DTD - PCDATA

46 DTD - CDATA

47 DTD - XML Building Blocks

48 DTD - Elements Webpage for more details

49 DTD - Elements

50 50 From Stanford: Element Descriptions Subtags must appear in order shown. A tag may be followed by a symbol to indicate its multiplicity. – * = zero or more. – + = one or more. – ? = zero or one. Symbol | can connect alternative sequences of tags.

51 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29

52 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????

53 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => YES

54 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????

55 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => NO

56 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => NO

57 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????

58 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => YES

59 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????

60 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => No

61 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document???? => No

62 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????

63 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????=>NO

64 DTD – Elements-Quiz http://zvon.org/comp/r/tut-DTD.html#Pages~Elements_in_given_order_%28_%2C_%29 tutorial.dtd Valid XML document????=>NO

65 65 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.? 2.?

66 66 From Stanford: Example: (a) <!DOCTYPE BARS [ ]> Joe’s Bar Bud 2.50 Miller 3.00 … The DTD The document 1.?

67 DTD - XML Building Blocks

68 68 From Standford:DTD Structure [ ( )>... more elements... ]>

69 XML Basics: Content of Week 5 DOM (Reviews) XML DTD XML Schema Lab: DTD and Schema construction

70 Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul Kwanchai@rmutl.ac.th

71 Week-1-Homework Marking criteria. 1.You have successfully created your database. (2.5 marks) 2.You have successfully populated your data into your big table. (2.5 marks) 3.You have successfully populated your data into your normalized tables (2.5 marks) 4.Your have demonstrated the enforcement of foreign key constraints for your database. (2.5 marks)

72 Homework-Week-2 1.Data Population (Normalization from last week) 1 2.HTML processing 4 3.Venn Diagram Creation 4

73 Lab for Week-3 1.Marking Week-2 Lab 2.Hand-Draw an XML tree structure for the given example in the class. (2.5) 3.Program-Draw an XML tree structure for an html data (from line 393 - 557) 1.http://elearning.rmutl.ac.th/main/file.php/542/wee k-2/thailand.htm (2.5)http://elearning.rmutl.ac.th/main/file.php/542/wee k-2/thailand.htm 4.Change the Xpath expression of your previous code to … and observe what is different (5)

74 Contents Week-4 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

75 Lab for Week-4 1.Write “SQL statements” to populate data into the following schema 2.Create indexes to speed up the join of these tables. 3.Create a program to retrieve data from the web and populated into your tables – Province coords – Amphur coords

76 Lab for Week-4-Cont.

77 Week-4 Homework Explain

78 ID Structure province-district_name-sub_district_name- moo 50-02-09-13 จังหวัด - อำเภอ - ตำบล - หมู่ => รหัสหมู่บ้าน เชียงใหม่ - จอมทอง - แม่สอย - หมู่ 13 => หมู่บ้าน ห้วยพัฒนา 50-03-01-02 เชียงใหม่ - แม่แจ่ม - ช่างเคิ้ง - หมู่ 2 => หมู่บ้านต่อ เรือ

79 How about ID like ‘000001’? In INT format? => ‘1’ => We will loose ‘00000’ So char(6) will be a solution. From: refman-5.5-en.html-chapter/data-types.html#numeric-types As an extension to the standard MEDIUMINT MySQL supports the SQL standard integer types INTEGER (or INT) and SMALLINT. As an extension to the standard, MySQL also supports the integer types TINYINT, MEDIUMINT, and BIGINT.

80 Let’s analyze the possible ID for regions SQL Here to get => Villagedata

81 Let’s analyze the possible ID for regions Villagedata

82 How about? select DISTINCT left(village_id,1), DISTINCT region_name from villagedata;

83 How about? select DISTINCT left(village_id,1), DISTINCT region_name from villagedata; Error

84 Contents Week-4 Create table – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

85 Now we need to construct region table Select name, collation, engine

86 What is collation???

87 Now we need to construct region table What is collation ?

88

89 Now we need to construct region table Select name, collation, engine

90

91 Collation http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-sets.html utf8, a UTF-8 encoding of the Unicode character set using one to three bytes per character http://dictionary.cambridge.org/dictionary/american-english/collate?q=collate =>to collect and arrange in correct order the sheets of a document

92 9.1.1. Character Sets and Collations in General

93 Let’s have a look http://www.collation-charts.org/mysql60/mysql604.utf8_unicode_ci.south_east_asian.html What are these?

94 Let’s have a look http://www.collation-charts.org/mysql60/mysql604.utf8_unicode_ci.south_east_asian.html

95

96 Let’s have a look http://www.collation-charts.org/mysql60/mysql604.utf8_unicode_ci.south_east_asian.html

97 Collation http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-sets.html What collation should we use?

98 Collation http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-sets.html

99 Collation => การเรียงลำดับตัวอักษร http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-sets.html We use utf8_unicode_ci because it provides more correct Comparison for foreign characters, e.g. B => ‘ss’ in stead of ‘s’. Note it will be slower than utf8_general_ci for comparison.

100 Now we need to construct region table What is collation ?

101 Now we need to construct region table Select name, collation, engine

102 Database Engine Selection EB = 10E+18 http://dev.mysql.com/doc/refman/5.6/en/storage- engines.html

103 Database Engine Selection So we will use InnoDB because we want Transaction and Foreign key support. EB = 10E+18 http://dev.mysql.com/doc/refman/5.6/en/storage- engines.html

104 Create table region

105

106 Synchronize with DB CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( `idregion` CHAR(1) NOT NULL, `nameregion` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`idregion`) ) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 COLLATE = utf8_unicode_ci;

107 Synchronize with DB 1.CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( 2. `idregion` CHAR(1) NOT NULL, 3. `nameregion` VARCHAR(45) NOT NULL, 4. PRIMARY KEY (`idregion`) ) 5.ENGINE = InnoDB 6.DEFAULT CHARACTER SET = utf8 7.COLLATE = utf8_unicode_ci; 8.DROP TABLE IF EXISTS `sml_test`.`tb_region` ; 9.DROP TABLE IF EXISTS `sml_test`.`tb_province` ;

108 Synchronize with DB 1.CREATE TABLE IF NOT EXISTS `sml_test`.`region` ( 2. `idregion` CHAR(1) NOT NULL, 3. `nameregion` VARCHAR(45) NOT NULL, 4. PRIMARY KEY (`idregion`) ) 5.ENGINE = InnoDB 6.DEFAULT CHARACTER SET = utf8 7.COLLATE = utf8_unicode_ci; 8.DROP TABLE IF EXISTS `sml_test`.`tb_region` ; 9.DROP TABLE IF EXISTS `sml_test`.`tb_province` ;

109 Contents Week-3 Constraints Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Select Data into table XML Basics – XML Quizs – http://www.w3schools.com/xml/ http://www.w3schools.com/xml/

110 Let’s analyze the possible ID for regions

111 What is wrong?

112 Drop primary key of region Now please write down an SQL statement to insert into the region table.

113 Insert into region insert into select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

114 Insert into region insert into select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

115 Insert into region insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

116 Insert into region insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata;

117 What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; Single column is duplicated

118 What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

119 What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

120 What should be primary key? insert into region select distinct left(village_id,1) as idregion, region_name as nameregion from villagedata; How about two columns for PK.

121 What should be primary key? How about two columns for PK.

122 Synchronize database Alter table sml_test.region Add primary key(idregion, nameregion); Data still exists

123 Contents Week-4 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

124 Join Optimization 80,000 8,000 80080 8

125 Join Optimization 80,000 8,000 80080 8 How about join them back together?

126 Join Optimization 80,000 8,000 80080 8 How about join them back together?

127 Response Time-1 -- Second query select region_name, prov_name,amp_name from region r, province p, amphur a where r.region_id = p.region_id and p.prov_id = a.prov_id;

128 Response Time-2 select region_name, prov_name,amp_name, tam_name from region r, province p, amphur a, tambon t where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id;

129 Response Time-3 select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

130 Join Optimization How about join them back together? 80,000 8,000 80080 8

131 phpMyAdmin

132 How to speed up a join?

133 Create Index http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html

134 How to speed up a join? Create Index http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html

135 How to speed up a join? Create Index http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html

136 How to speed up a join? Create Index Which table should be considered? Which column should be considered? http://dev.mysql.com/doc/refman/5.6/en/mysql-indexes.html 80,000 8,000 80080 8

137 Create Index Village Table

138 Response Time-3 select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

139 What if We remove an index on village.tam_id? select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id;

140 What if We remove an index on village.tam_id? select region_name, prov_name,amp_name, tam_name, vill_name from region r, province p, amphur a, tambon t, village v where r.region_id = p.region_id and p.prov_id = a.prov_id and a.amp_id = t.amp_id and t.tam_id = v.tam_id; remove an index Has an index

141 Where else that we can add indexes?

142 Can we create index on every column?

143 Where else that we can add indexes? Can we create index on every column? http://en.wikipedia.org/wiki/B-tree

144 Contents Week-3 Create table using MySQL Workbench – Collation => Sorting => UTF-8_general/unicode – Storage Engine => MyISAM, InnoDB Populate Data: Select Data into table Join Optimization XML Basics – DOM

145 DOM

146 XML => Book

147

148 DOM Nodes

149 Node Tree

150 Node Type Property

151

152 Node List

153

154

155 DOM XPath::query Returns a DOMNodeList containing all nodes matching the given XPath expression http://th.php.net/manual/en/domxpath.query.php

156 DOM $my_xpath_query = "/";

157 DOM $my_xpath_query = "//area/@coords";

158 DOM $my_xpath_query = "//area[(./@coords != 0) and (./@href != '#')]";

159 DOM $my_xpath_query = "//area[(./@coords != 0) and (./@href != '#')]";

160 Week-4-Home-Work

161 End of Week-4 Lecture


Download ppt "Advance Database S2-2011 Week-5 Dr.Kwanchai Eurviriyanukul"

Similar presentations


Ads by Google