cvs: presentations / db-phptek6.xml /slides/dbdesign 1-n-naming.png IMG_3922.JPG air.png assignment1.xml assignment2.xml auto-increment.xml
auto-increment2.xml break.png break.xml column-types.xml content.xml create-table1.xml create-table2.xml create-table3.xml delete-fk.png
denormalization1.png denormalization1.xml denormalization2.png denormalization2.xml denormalization3.png denormalization3.xml denormalization4.xml
denormalization5.xml diagram-fk.png foreign-keys.xml foreign-keys2.xml foreign-keys3.xml foreign-keys4.xml index.xml intregity.xml naming-columns.xml
normal-fk1.png normal-fk2.png null-values-in-columns.xml path1.png paths-adding-node.xml paths-selecting-path.xml paths-selecting-subtree.xml
paths.xml questions.xml tips.png tips.xml tree-nested-set1.xml tree-nested-set2.xml tree-nested-set3.xml tree-nested-set4.xml tree.jpg tree3.png
tree4.png tree5.png trees.xml trees2.xml trigger1.xml trigger2.xml /slides/phpperform visitation3.xml visitation4.xml! visitation5.xml

From: Date: Tue, 25 Apr 2006 20:29:48 +0000
Subject: cvs: presentations / db-phptek6.xml /slides/dbdesign 1-n-naming.png IMG_3922.JPG air.png assignment1.xml assignment2.xml auto-increment.xml
auto-increment2.xml break.png break.xml column-types.xml content.xml create-table1.xml create-table2.xml create-table3.xml delete-fk.png
denormalization1.png denormalization1.xml denormalization2.png denormalization2.xml denormalization3.png denormalization3.xml denormalization4.xml
denormalization5.xml diagram-fk.png foreign-keys.xml foreign-keys2.xml foreign-keys3.xml foreign-keys4.xml index.xml intregity.xml naming-columns.xml
normal-fk1.png normal-fk2.png null-values-in-columns.xml path1.png paths-adding-node.xml paths-selecting-path.xml paths-selecting-subtree.xml
paths.xml questions.xml tips.png tips.xml tree-nested-set1.xml tree-nested-set2.xml tree-nested-set3.xml tree-nested-set4.xml tree.jpg tree3.png
tree4.png tree5.png trees.xml trees2.xml trigger1.xml trigger2.xml /slides/phpperform visitation3.xml visitation4.xml! visitation5.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1301@lists.php.net to get a copy of this message
derick Tue Apr 25 20:29:48 2006 UTC Added files: /presentations/slides/dbdesign 1-n-naming.png IMG_3922.JPG air.png assignment1.xml assignment2.xml auto-increment.xml auto-increment2.xml break.png break.xml column-types.xml create-table1.xml create-table2.xml create-table3.xml delete-fk.png denormalization1.png denormalization1.xml denormalization2.png denormalization2.xml denormalization3.png denormalization3.xml denormalization4.xml denormalization5.xml diagram-fk.png foreign-keys.xml foreign-keys2.xml foreign-keys3.xml foreign-keys4.xml index.xml intregity.xml normal-fk1.png normal-fk2.png null-values-in-columns.xml path1.png paths-adding-node.xml paths-selecting-path.xml paths-selecting-subtree.xml paths.xml questions.xml tips.png tips.xml tree-nested-set1.xml tree-nested-set2.xml tree-nested-set3.xml tree-nested-set4.xml tree.jpg tree3.png tree4.png tree5.png trees.xml trees2.xml trigger1.xml trigger2.xml Modified files: /presentations db-phptek6.xml /presentations/slides/dbdesign content.xml naming-columns.xml /presentations/slides/phpperform visitation3.xml visitation4.xml visitation5.xml Log: - Added the test of the DB talk.

http://cvs.php.net/viewcvs.cgi/presentations/db-phptek6.xml?r1=1.1&r2=1.2&diff_format=u Index: presentations/db-phptek6.xml diff -u presentations/db-phptek6.xml:1.1 presentations/db-phptek6.xml:1.2 --- presentations/db-phptek6.xml:1.1 Sun Apr 23 19:07:03 2006 +++ presentations/db-phptek6.xml Tue Apr 25 20:29:47 2006 @@ -41,16 +41,53 @@ <slide>slides/dbdesign/relations-n-m.xml</slide> <slide>slides/dbdesign/singular-vs-plural-names.xml</slide> <slide>slides/dbdesign/naming-columns.xml</slide> -<slide>slides/dbdesign/in-sql.xml</slide> + +<!-- ASSIGNMENT 1 --> +<slide>slides/dbdesign/assignment1.xml</slide> +<slide>slides/dbdesign/break.xml</slide> + +<!-- SQL DDL --> <slide>slides/dbdesign/column-types.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> -<slide>slides/dbdesign/.xml</slide> +<slide>slides/dbdesign/null-values-in-columns.xml</slide> +<slide>slides/dbdesign/auto-increment.xml</slide> +<slide>slides/dbdesign/auto-increment2.xml</slide> +<slide>slides/dbdesign/create-table1.xml</slide> +<slide>slides/dbdesign/create-table3.xml</slide> +<slide>slides/dbdesign/create-table2.xml</slide> +<slide>slides/dbdesign/intregity.xml</slide> +<slide>slides/dbdesign/foreign-keys.xml</slide> +<slide>slides/dbdesign/foreign-keys2.xml</slide> +<slide>slides/dbdesign/foreign-keys3.xml</slide> +<slide>slides/dbdesign/foreign-keys4.xml</slide> + +<slide>slides/dbdesign/index.xml</slide> + +<!-- ASSIGNMENT 2 --> +<slide>slides/dbdesign/assignment2.xml</slide> +<slide>slides/dbdesign/break.xml</slide> + +<!-- DENORMALIZATION/TRIGGERS --> +<slide>slides/dbdesign/denormalization1.xml</slide> +<!-- Example 1 --> +<slide>slides/dbdesign/denormalization2.xml</slide> +<slide>slides/dbdesign/denormalization3.xml</slide> + +<slide>slides/dbdesign/trigger1.xml</slide> +<slide>slides/dbdesign/trigger2.xml</slide> +<!-- TIPS & TRICKS --> +<slide>slides/dbdesign/tips.xml</slide> +<slide>slides/hpp/mysql_opt2.xml</slide> +<slide>slides/dbdesign/trees.xml</slide> +<slide>slides/dbdesign/trees2.xml</slide> +<slide>slides/dbdesign/tree-nested-set1.xml</slide> +<slide>slides/dbdesign/tree-nested-set2.xml</slide> +<slide>slides/dbdesign/tree-nested-set3.xml</slide> +<slide>slides/dbdesign/tree-nested-set4.xml</slide> +<slide>slides/dbdesign/paths.xml</slide> +<slide>slides/dbdesign/paths-adding-node.xml</slide> +<slide>slides/dbdesign/paths-selecting-path.xml</slide> +<slide>slides/dbdesign/paths-selecting-subtree.xml</slide> +<slide>slides/dbdesign/questions.xml</slide> </presentation> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/content.xml?r1=1.1&r2=1.2&diff_format=u Index: presentations/slides/dbdesign/content.xml diff -u presentations/slides/dbdesign/content.xml:1.1 presentations/slides/dbdesign/content.xml:1.2 --- presentations/slides/dbdesign/content.xml:1.1 Sun Apr 23 19:07:03 2006 +++ presentations/slides/dbdesign/content.xml Tue Apr 25 20:29:47 2006 @@ -15,7 +15,6 @@ <bullet>Indexes</bullet> <bullet>Denormalization</bullet> <bullet>Triggers</bullet> - <bullet>Stored Procedures</bullet> </list> <blurb>Tips &amp; Tricks</blurb> <list> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/naming-columns.xml?r1=1.1&r2=1.2&diff_format=u Index: presentations/slides/dbdesign/naming-columns.xml diff -u presentations/slides/dbdesign/naming-columns.xml:1.1 presentations/slides/dbdesign/naming-columns.xml:1.2 --- presentations/slides/dbdesign/naming-columns.xml:1.1 Sun Apr 23 19:07:03 2006 +++ presentations/slides/dbdesign/naming-columns.xml Tue Apr 25 20:29:47 2006 @@ -3,11 +3,13 @@ <title>Naming Columns</title> <blurb>Normal columns are straight forward.</blurb> - +<break/> <blurb>For columns that refer to another table, it is useful to:</blurb> <list> - <bullet> - </bullet> + <bullet>Prefix them with the table name they refer to.</bullet> + <bullet>Use the same name as the column name in the table it is referred to.</bullet> </list> +<break lines="2"/> + <image filename="1-n-naming.png" /> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/phpperform/visitation3.xml?r1=1.4&r2=1.5&diff_format=u Index: presentations/slides/phpperform/visitation3.xml diff -u presentations/slides/phpperform/visitation3.xml:1.4 presentations/slides/phpperform/visitation3.xml:1.5 --- presentations/slides/phpperform/visitation3.xml:1.4 Wed Mar 23 12:36:11 2005 +++ presentations/slides/phpperform/visitation3.xml Tue Apr 25 20:29:48 2006 @@ -7,7 +7,8 @@ <image align="center" filename="tree3.png" /> <blurb fontsize="5em">Query:</blurb> - <example class="large"><![CDATA[SELECT * FROM directory +<break/> + <example><![CDATA[SELECT * FROM directory WHERE left <= 5 AND right >= 6]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/phpperform/visitation4.xml?r1=1.3&r2=1.4&diff_format=u Index: presentations/slides/phpperform/visitation4.xml diff -u presentations/slides/phpperform/visitation4.xml:1.3 presentations/slides/phpperform/visitation4.xml:1.4 --- presentations/slides/phpperform/visitation4.xml:1.3 Wed Mar 23 12:36:11 2005 +++ presentations/slides/phpperform/visitation4.xml Tue Apr 25 20:29:48 2006 @@ -7,7 +7,8 @@ <image align="center" filename="tree4.png" /> <blurb fontsize="5em">Query:</blurb> - <example class="large"><![CDATA[SELECT * FROM directory +<break/> + <example><![CDATA[SELECT * FROM directory WHERE right - left = 1]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/phpperform/visitation5.xml?r1=1.3&r2=1.4&diff_format=u Index: presentations/slides/phpperform/visitation5.xml diff -u presentations/slides/phpperform/visitation5.xml:1.3 presentations/slides/phpperform/visitation5.xml:1.4 --- presentations/slides/phpperform/visitation5.xml:1.3 Wed Mar 23 12:36:11 2005 +++ presentations/slides/phpperform/visitation5.xml Tue Apr 25 20:29:48 2006 @@ -7,7 +7,8 @@ <image align="center" filename="tree5.png" /> <blurb fontsize="5em">Query:</blurb> - <example class="large"><![CDATA[SELECT * FROM directory +<break/> + <example><![CDATA[SELECT * FROM directory WHERE left >= 4 AND right <= 9]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/assignment1.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/assignment1.xml +++ presentations/slides/dbdesign/assignment1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Assignment #1</title> <blurb>Design a database (as ERD) to store the following data:</blurb> <list> <bullet>~Derick~ has a ~return~ ticket on ~Monday April 24th, 2006~ from ~TRF (Torp)~ to ~MCO (Orlando)~ and back on ~April 29th~</bullet> <bullet>The flight trom ~Torp~ to ~Orlando~ consists of: ~TRF to AMS (Amsterdam)~, ~AMS to DTW (Detroit)~ and ~DTW to MCO~, the way back goes ~MCO->MEM (Memphis)->AMS->TRF~</bullet> <bullet>~Flight KL 1212~ leaves ~every day~ at ~06:25~ and goes from ~TRF to AMS~</bullet> <bullet>~Flight KL 1221~ leaves on ~all days, except Saturday~ at ~15:30~ from ~AMS to TRF~</bullet> <bullet>Flight ~KL 1212~ and ~KL 1221~ takes ~1h40m~</bullet> <bullet>~Derick~ has a ~single~ ticket on ~Saturday May 13th~ from ~AMS to TRF~.</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/assignment2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/assignment2.xml +++ presentations/slides/dbdesign/assignment2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Assignment #2</title> <blurb>Write down (or try with MySQL) the SQL (including possible useful indexes and constraints) of the %flight% and %airport_code% tables from the following diagram:</blurb> <break lines="2"/> <image filename="air.png"/> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/auto-increment.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/auto-increment.xml +++ presentations/slides/dbdesign/auto-increment.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Auto Increment</title> <list> <bullet>Generates the 'next' number upon insert</bullet> <bullet>Often used for surrogate keys</bullet> <bullet>In some database not available directly, but only through a sequence</bullet> <bullet>Column must defined as "%integer not null%"</bullet> <bullet>They can not be cleaned up</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/auto-increment2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/auto-increment2.xml +++ presentations/slides/dbdesign/auto-increment2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Auto Increment</title> <blurb> The following has been editted to fix spelling errors and to protect the guilty: </blurb> <break/> <example><![CDATA[user: I'm having a problem with my MySQL database :) user: I have a Table with Field1, which has auto_increment attribute user: Table has three records, with Field1 numbered 1, 2 and 3 user: now I'm using delete from Table where Field1 = 2 limit 1; user: and next id is 4.. user: but I want it to use 2 user: I read something about resetting auto_increment.. is that the way to fix it then? user: I'll run out of id's otherwise user: but the thing is, this company wants to add a lot of pictures to their database user: because selling pictures is what they do :) user: now I made Field1 unsigned int, but what if it turns out to be not enough? user: but, just out of curiosity.. is there a way to fill up gaps with auto_increment? :)]]></example> <list> <bullet>unsigned int is enough!</bullet> <bullet> for unsigned int the company has to hire 20 photographers which have to shoot 1000 pictures per day. Then they have to work 588 years until you run out of id's </bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/break.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/break.xml +++ presentations/slides/dbdesign/break.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Break</title> <break lines="8"/> <image filename="break.png" /> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/column-types.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/column-types.xml +++ presentations/slides/dbdesign/column-types.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Column Types</title> <blurb> A column can have a different datatype. Datatypes are often RDBMS dependent, but there are often equivalent types with a slightly different name. </blurb> <break/> <blurb> The following types are often available: </blurb> <list> <bullet>*integer*: to store integral numbers</bullet> <bullet>*float*: to store floating point values</bullet> <bullet>*varchar*: to store variable length strings</bullet> <bullet>*char*: to store fixed length strings</bullet> <bullet>*date*: to store dates</bullet> <bullet>*timestamp*: to store timestamps</bullet> <bullet>*blob*: to store (large) amounts binary data</bullet> <bullet>*clob* or *text*: to store (large) amounts of text</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/create-table1.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/create-table1.xml +++ presentations/slides/dbdesign/create-table1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>CREATE TABLE</title> <table columns="2" class="dbtable" title="Country"> <cell class="header-key">Code</cell><cell class="header">Name</cell> <cell>NL</cell><cell>Netherlands</cell> <cell>NO</cell><cell>Norway</cell> </table> <break/> <example><![CDATA[CREATE TABLE country ( code CHAR(2) NOT NULL, name VARCHAR(64) NOT NULL, PRIMARY KEY (code) ) ENGINE=InnoDB;]]></example> <break lines="2"/> <table columns="2" class="dbtable" title="Developer"> <cell class="header-key">Name</cell><cell class="header">Country Code</cell> <cell>Derick</cell><cell>NL</cell> <cell>Sergey</cell><cell>NO</cell> </table> <break/> <example><![CDATA[CREATE TABLE developer ( name VARCHAR(64) NOT NULL, country_code CHAR(2) NOT NULL, PRIMARY KEY (name) ) ENGINE=InnoDB;]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/create-table2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/create-table2.xml +++ presentations/slides/dbdesign/create-table2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>CREATE TABLE</title> <subtitle>part 3</subtitle> <table columns="4" class="dbtable" title="ComponentVersion"> <cell class="header-key">ID</cell><cell class="header-candidate-key">Component</cell><cell class="header-candidate-key">Component Version</cell><cell class="header">Release Date</cell> <cell>1</cell><cell>Base</cell><cell>1.0</cell><cell>2006-01-07</cell> <cell>3</cell><cell>Base</cell><cell>1.1</cell><cell>~NULL~</cell> </table> <break/> <example><![CDATA[CREATE TABLE component_version ( id INT NOT NULL AUTO_INCREMENT, component_name VARCHAR(64) NOT NULL, component_version VARCHAR(16) NOT NULL, release_date date, PRIMARY KEY (id), UNIQUE KEY name_version (component_name, component_version) ) ENGINE=InnoDB;]]></example> <break lines="2"/> <table columns="2" class="dbtable" title="DeveloperComponentVersion"> <cell class="header-key">Component Version ID</cell><cell class="header-key">Developer Name</cell> <cell>1</cell><cell>Derick</cell> <cell>3</cell><cell>Sergey</cell> </table> <break/> <example><![CDATA[CREATE TABLE developer_component_version ( component_version_id INTEGER NOT NULL, developer_name VARCHAR(64) NOT NULL, PRIMARY KEY (component_version_id, developer_name) ) ENGINE=InnoDB;]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/create-table3.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/create-table3.xml +++ presentations/slides/dbdesign/create-table3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>CREATE TABLE</title> <subtitle>part 2</subtitle> <table columns="3" class="dbtable" title="Component"> <cell class="header-key">Name</cell><cell class="header">Priority</cell><cell class="header">Main Developer Name</cell> <cell>DatabaseSchema</cell><cell>2</cell><cell>Derick</cell> <cell>Database</cell><cell>3</cell><cell>~NULL~</cell> </table> <break/> <example><![CDATA[CREATE TABLE component ( name VARCHAR(64) NOT NULL, priority INT NOT NULL, main_developer_name VARCHAR(64), PRIMARY KEY (name) ) ENGINE=InnoDB;]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/denormalization1.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/denormalization1.xml +++ presentations/slides/dbdesign/denormalization1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <list> <bullet>Denormalization is the process of reverting a database schema to a lower NF</bullet> <bullet>Denormalization is often done to enhance performance</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/denormalization2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/denormalization2.xml +++ presentations/slides/dbdesign/denormalization2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <subtitle>Example 1</subtitle> <image filename="denormalization1.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <blurb>Usually you always want to display the name of the airfield instead of the airport code. But in the current diagram you always have to use a join for this:</blurb> <break/> <example><![CDATA[SELECT tp.date, tp.sequence, fa.airfield_name, ta.airfield_name FROM trip_part tp JOIN flight f ON tp.flight_carrier = f.carrier AND tp.flight_nr = f.flight_nr JOIN airport_code fa ON f.from_airport = fa.code JOIN airport_code ta ON f.to_airport = ta.code WHERE tp.trip_id = 1 ORDER BY tp.sequence;]]></example> <break/> <example><![CDATA[+------------+----------+---------------+---------------+ | date | sequence | airfield_name | airfield_name | +------------+----------+---------------+---------------+ | 2006-04-24 | 1 | Sandefjord | Amsterdam | | 2006-04-24 | 2 | Amsterdam | Detroit | | 2006-04-24 | 3 | Detroit | Orlando | +------------+----------+---------------+---------------+]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/denormalization3.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/denormalization3.xml +++ presentations/slides/dbdesign/denormalization3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <subtitle>Example 1 (part deux)</subtitle> <image filename="denormalization2.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <blurb>Usually you always want to display the name of the airfield instead of the airport code. But in the current diagram you always have to use a join for this:</blurb> <break/> <example><![CDATA[SELECT tp.date, tp.sequence, fd.from_airfield_name, fd.to_airfield_name FROM trip_part tp JOIN flight_denorm fd ON tp.flight_carrier = fd.carrier AND tp.flight_nr = fd.flight_nr WHERE tp.trip_id = 1 ORDER BY tp.sequence;]]></example> <break/> <example><![CDATA[+------------+----------+--------------------+------------------+ | date | sequence | from_airfield_name | to_airfield_name | +------------+----------+--------------------+------------------+ | 2006-04-24 | 1 | Sandefjord | Amsterdam | | 2006-04-24 | 2 | Amsterdam | Detroit | | 2006-04-24 | 3 | Detroit | Orlando | +------------+----------+--------------------+------------------+]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/denormalization4.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/denormalization4.xml +++ presentations/slides/dbdesign/denormalization4.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <subtitle>Example 2</subtitle> <image filename="denormalization3.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <break/> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/denormalization5.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/denormalization5.xml +++ presentations/slides/dbdesign/denormalization5.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <subtitle>Example 2 (part deux)</subtitle> <image filename="denormalization4.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <break/> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/foreign-keys.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/foreign-keys.xml +++ presentations/slides/dbdesign/foreign-keys.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Foreign Keys</title> <list> <bullet>Foreign keys act as constraints to guard against data inconsistency</bullet> <bullet>They make sure that data which is refered to is actually there</bullet> <bullet>Can be set-up in such a way so that refered data is automatically removed</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/foreign-keys2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/foreign-keys2.xml +++ presentations/slides/dbdesign/foreign-keys2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding the Foreign Keys</title> <image filename="normal-fk1.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <example><![CDATA[ALTER TABLE developer ADD CONSTRAINT developer_country_code FOREIGN KEY (country_code) REFERENCES country(code); ALTER TABLE component ADD CONSTRAINT component_developer_name FOREIGN KEY (main_developer_name) REFERENCES developer(name); ]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/foreign-keys3.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/foreign-keys3.xml +++ presentations/slides/dbdesign/foreign-keys3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding the Foreign Keys</title> <subtitle>part 2</subtitle> <image filename="normal-fk2.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <example><![CDATA[ALTER TABLE developer_component_version ADD CONSTRAINT developer_component_version_developer FOREIGN KEY (developer_name) REFERENCES developer(name), ADD CONSTRAINT developer_component_version_component_version FOREIGN KEY (component_version_id) REFERENCES component_version(id);]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/foreign-keys4.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/foreign-keys4.xml +++ presentations/slides/dbdesign/foreign-keys4.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Adding the Foreign Keys</title> <subtitle>part 3</subtitle> <image filename="delete-fk.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <example><![CDATA[ALTER TABLE component_version ADD CONSTRAINT component_version_component FOREIGN KEY (component_name) REFERENCES component(name) ON DELETE CASCADE ON UPDATE CASCADE;]]></example> <list> <bullet>%ON DELETE CASCADE%: If a by %component_version% referenced value is delete from %component%, also delete all the corresponding records in this table</bullet> <bullet>%ON UPDATE CASCADE%: If a by %component_version% referenced value in %component% changes due to an %UPDATE% query, update the values in %component_version% too</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/index.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/index.xml +++ presentations/slides/dbdesign/index.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Indexes</title> <list> <bullet>An %index% orders data for fast retrieval</bullet> <bullet>Indexes can be used for querying or sorting</bullet> <bullet>Indexes also use memory</bullet> </list> <table columns="4" class="dbtable" title="ComponentVersion"> <cell class="header-key">ID</cell><cell class="header-candidate-key">Component</cell><cell class="header-candidate-key">Component Version</cell><cell class="header">Release Date</cell> <cell>1</cell><cell>Base</cell><cell>1.0</cell><cell>2006-01-07</cell> <cell>3</cell><cell>Base</cell><cell>1.1</cell><cell>~NULL~</cell> </table> <break/> <blurb>Searching for all releases in Q1 does not use an index:</blurb> <break/> <example><![CDATA[EXPLAIN SELECT * FROM component_version WHERE release_date BETWEEN '2006-01-01' AND '2006-03-31';]]></example> <break/> <blurb>Create an index with:</blurb> <break/> <example><![CDATA[ALTER TABLE component_version ADD INDEX component_version_release_date (release_date);]]></example> <break/> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/intregity.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/intregity.xml +++ presentations/slides/dbdesign/intregity.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Intregity</title> <list> <bullet>In our current database there is no intregity checking</bullet> <bullet>Data in a table's record might refer to another table without that data being present: inconsistent data</bullet> <bullet>~Referential Intregity~</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/null-values-in-columns.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/null-values-in-columns.xml +++ presentations/slides/dbdesign/null-values-in-columns.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>NULL</title> <list> <bullet>"%NULL%" is a special value</bullet> <bullet>"%NULL%" is neither TRUE or FALSE</bullet> <bullet>"%NULL = NULL%" evaluates to FALSE</bullet> <bullet>"%NULL IS NULL%" evaluates to TRUE</bullet> <bullet>Columns can be defined as "%NULL%" (default) or "%NOT NULL%"</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/paths-adding-node.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/paths-adding-node.xml +++ presentations/slides/dbdesign/paths-adding-node.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Path Strings</title> <example><![CDATA[Id | ParentId | PathString | Name | Depth ---+----------+-------------+--------------+------ 87 | 2 | /87/ | Countries | 2 88 | 87 | /87/88/ | Belgium | 3 89 | 87 | /87/89/ | Netherlands | 3 91 | 89 | /87/89/91/ | Business | 4 92 | 89 | /87/89/92/ | Economy | 4 90 | 87 | /87/90/ | Germany | 3]]></example> <break/> <blurb>Adding a node:</blurb> <break/> <example><![CDATA[function add_node( parent, name ) { $parent_info = SELECT * FROM tree WHERE Id = $parent; INSERT INTO tree(Id, Name) VALUES( NULL, $name ); $last_id = LAST INSERT ID; UPDATE tree SET ParentId = $parent, PathString = $parent_info['PathString'] . $last_id . "/", Depth = $parent['Depth'] + 1 WHERE Id = $last_id }]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/paths-selecting-path.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/paths-selecting-path.xml +++ presentations/slides/dbdesign/paths-selecting-path.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Path Strings</title> <example><![CDATA[Id | ParentId | PathString | Name | Depth ---+----------+-------------+--------------+------ 87 | 2 | /87/ | Countries | 2 88 | 87 | /87/88/ | Belgium | 3 89 | 87 | /87/89/ | Netherlands | 3 91 | 89 | /87/89/91/ | Business | 4 92 | 89 | /87/89/92/ | Economy | 4 90 | 87 | /87/90/ | Germany | 3]]></example> <break/> <blurb>Selecting the path:</blurb> <break/> <example><![CDATA[function select_path( id ) { $info = SELECT * FROM tree WHERE Id = $id; $parts = array_slice( split( '/', $info['PathString'] ), 1, -1 ); $path = SELECT Id, Name FROM tree WHERE Id in $parts; return $path; }]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/paths-selecting-subtree.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/paths-selecting-subtree.xml +++ presentations/slides/dbdesign/paths-selecting-subtree.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Path Strings</title> <example><![CDATA[Id | ParentId | PathString | Name | Depth ---+----------+-------------+--------------+------ 87 | 2 | /87/ | Countries | 2 88 | 87 | /87/88/ | Belgium | 3 89 | 87 | /87/89/ | Netherlands | 3 91 | 89 | /87/89/91/ | Business | 4 92 | 89 | /87/89/92/ | Economy | 4 90 | 87 | /87/90/ | Germany | 3]]></example> <break/> <blurb>Selecting a subtree:</blurb> <break/> <example><![CDATA[function select_subtree( id ) { $info = SELECT PathString FROM tree WHERE Id = $id; $tree_elements = SELECT * FROM tree WHERE PathString LIKE "$info%"; return $tree_elements; }]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/paths.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/paths.xml +++ presentations/slides/dbdesign/paths.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide fontsize="6em"> <title>Different Approach</title> <image align="center" filename="path1.png" /> <blurb fontsize="5em">Path strings:</blurb> <break/> <example><![CDATA[Id | ParentId | PathString | Name | Depth ---+----------+-------------+--------------+------ 87 | 2 | /87/ | Countries | 2 88 | 87 | /87/88/ | Belgium | 3 89 | 87 | /87/89/ | Netherlands | 3 91 | 89 | /87/89/91/ | Business | 4 92 | 89 | /87/89/92/ | Economy | 4 90 | 87 | /87/90/ | Germany | 3]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/questions.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/questions.xml +++ presentations/slides/dbdesign/questions.xml <?xml version="1.0" encoding="iso-8859-1"?> <slide> <title>Questions and Resources</title> <blurb>Questions anybody?</blurb> <break lines="5"/> <blurb>Resources:</blurb> <list> <bullet>*These Slides*: :-:url:-:</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/tips.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/tips.xml +++ presentations/slides/dbdesign/tips.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Tips &amp; Tricks</title> <break lines="8"/> <image filename="tips.png" /> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/tree-nested-set1.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/tree-nested-set1.xml +++ presentations/slides/dbdesign/tree-nested-set1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Nested Set</title> <subtitle>Selecting The Path</subtitle> <image align="center" filename="tree3.png" /> <blurb>Query:</blurb> <break/> <example><![CDATA[SELECT * FROM directory WHERE left <= 5 AND right >= 6]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/tree-nested-set2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/tree-nested-set2.xml +++ presentations/slides/dbdesign/tree-nested-set2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Nested Set</title> <subtitle>Selecting All End Points</subtitle> <image align="center" filename="tree4.png" /> <blurb>Query:</blurb> <break/> <example><![CDATA[SELECT * FROM directory WHERE right - left = 1]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/tree-nested-set3.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/tree-nested-set3.xml +++ presentations/slides/dbdesign/tree-nested-set3.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Nested Set</title> <subtitle>Selecting A Subtree</subtitle> <image align="center" filename="tree5.png" /> <blurb>Query:</blurb> <break/> <example><![CDATA[SELECT * FROM directory WHERE left >= 4 AND right <= 9]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/tree-nested-set4.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/tree-nested-set4.xml +++ presentations/slides/dbdesign/tree-nested-set4.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Nested Set</title> <list> <bullet>Fast for reads and selection</bullet> <bullet>Doesn't scale well with adding nodes</bullet> <bullet>Doesn't scale well with moving nodes/subtrees</bullet> </list> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/trees.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/trees.xml +++ presentations/slides/dbdesign/trees.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Trees</title> <blurb> Trees do not really map well to relational databases. The most obvious way of storing them is like: </blurb> <image align="right" filename="tree.jpg" marginright="1em"/> <break lines="4"/> <table columns="3" class="dbtable" title="Tree"> <cell class="header-key">ID</cell><cell class="header">Parent ID</cell><cell class="header">Name</cell> <cell>3</cell><cell>1</cell><cell>Countries</cell> <cell>4</cell><cell>3</cell><cell>Belgium</cell> <cell>5</cell><cell>3</cell><cell>Netherlands</cell> <cell>6</cell><cell>3</cell><cell>Germany</cell> <cell>7</cell><cell>5</cell><cell>Business</cell> <cell>8</cell><cell>5</cell><cell>Economy</cell> </table> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/trees2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/trees2.xml +++ presentations/slides/dbdesign/trees2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Trees</title> <table columns="3" class="dbtable" title="Tree"> <cell class="header-key">ID</cell><cell class="header">Parent ID</cell><cell class="header">Name</cell> <cell>3</cell><cell>1</cell><cell>Countries</cell> <cell>4</cell><cell>3</cell><cell>Belgium</cell> <cell>5</cell><cell>3</cell><cell>Netherlands</cell> <cell>6</cell><cell>3</cell><cell>Germany</cell> <cell>7</cell><cell>5</cell><cell>Business</cell> <cell>8</cell><cell>5</cell><cell>Economy</cell> </table> <break/> <blurb>Retrieving the full path to the root node goes with something like:</blurb> <break/> <example><![CDATA[<?php function collectPath( $id ) { global $dir; $res = mysql_query( "SELECT parent, name FROM dir WHERE id=$id" ); if ( mysql_num_rows( $res ) > 0 ) { $dir[] = ( $row = mysql_fetch_row( $res ) ); collectPath( $row['parent'] ); } } $dir = array(); collectPath(7);]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/trigger1.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/trigger1.xml +++ presentations/slides/dbdesign/trigger1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Denormalization</title> <subtitle>Update Problems</subtitle> <image filename="denormalization2.png"/> <blurb>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</blurb> <blurb>If some airport changes name, you need to run multiple updates:</blurb> <break/> <example><![CDATA[UPDATE airport_code SET airfield_name = 'Montreal Pierre Trudeau' WHERE code = 'YUL'; UPDATE flight_denorm SET from_airfield_name = 'Montreal Pierre Trudeau' WHERE from_airport = 'YUL'; UPDATE flight_denorm SET to_airfield_name = 'Montreal Pierre Trudeau' WHERE to_airport = 'YUL';]]></example> </slide> http://cvs.php.net/viewcvs.cgi/presentations/slides/dbdesign/trigger2.xml?view=markup&rev=1.1 Index: presentations/slides/dbdesign/trigger2.xml +++ presentations/slides/dbdesign/trigger2.xml <?xml version="1.0" encoding="ISO-8859-1"?> <slide> <title>Trigger</title> <subtitle>Update Problems</subtitle> <blurb>A better solution is a trigger:</blurb> <break/> <example><![CDATA[]]></example> </slide>
« previous php.pres (#1301) next »