SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Quick and Dirty Databases(and SQL) Chris Warren cwarren@williams.edu x4323         Jesup 312
Data Organization in Databases field (a.k.a. column) a bunch of fields make a record (a.k.a. row) a bunch of records make a table a bunch of tables make a database a bunch of databases make a DB system
Designing a (Relational) DB Entities and Entity Relationships (ERD) Normalizing Detailing Cleanup
Entities and Entity Relationships Entities (tables) ID (a.k.a. primary key) Entity Attributes (fields) Relationships 1-to-1 1-to-many or many-to-1 many-to-many
Relationships 1-to-1 usually data is in the same table 1-to-many and many-to-1 foreign key goes with the many entity many-to-many linking table with 2 foreign keys, one for each side
Create an ERD ERD = Entity Relationship Diagram Draw on paper Entities (tables) Relationships between them indicate type : 1-to-1, 1-to-many, many-to-many
Detail the ERD Finalize table names and list fields table name should be plural primary id is singular + _id add any foreign keys list fields include unit in name add is_ or flag_ or _flag for true/false fields
Normalizing Normalizing is basically removing duplication merge mostly similar tables  split out common field sets split out conceptually distinct field sets
Normalizing – Merge Tables tables have very similar field sets entities are both / all examples of a more general concept generalize the table name add a type field change foreign keys in other tables to include the type
Normalizing – Split Out Field Sets same list of field repeated in different tables group of fields describes a distinct concept create a new table for that new entity add a foreign key to the new table in each of the original tables
Normalizing – Split Out Concepts a table has multiple sub-parts common field name prefix is one indicator data would be repeated for many records create a new table for those fields add a foreign key to the original table
ERD Detailing create any grouping tables as needed add data types and descriptions to fields int varchar (string up to 255 characters) text (BIG string) date and/or time boolean (true/false)
ERD Cleanup add timestamps (created_at, updated_at) review relationships, fix as needed review fields, add any missing characteristics
ERD is DONE! Now you get to implement it...
SQL – Structured Query Language used to send commands to a database there’s a core standard, and a lot of vendor-specific minor changes / additions two branches data definition – create tables data manipulation – add, edit, retrieve, delete data http://dev.mysql.com/doc/refman/5.0/en/
SQL concepts (manipulation) Databases are a big pile of information Identify which piece of info you want to manipulate State how you want to manipulate it retrieve it edit it delete it add it
Writing SQL build it backwards.... what you want to do  select, update, delete, or insert where it is the table and row(s) the specific parts the fields
SQL Conventions SQL keywords in upper case Your info (tables, fields, etc) in lower case Indent each section of the statement Use multiple lines
SQL SELECT (most common) 3.the SELECT clause – which fields  SELECT fields FROM tables WHERE conditions GROUP BY non-aggregate fields ORDER BY fields 1.the FROM clause – which tables  2.the WHERE clause – which rows
SQL SELECT Example SELECT e.name FROM cwarren_equipment AS e 	,cwarren_location AS l WHERE e.location_id=l.location_id 	AND l.name=‘Lab 54’;
SQL SELECT Example SELECT e.name FROM cwarren_equipment AS e 	JOIN cwarren_location AS l ON 						e.location_id=l.location_id WHERE l.name=‘Lab 54’;
SQL UPDATE UPDATE TABLE table SET  field1=newval1 ,field2=newval2,... WHERE conditions
SQL INSERT INSERT INTO table VALUES (v1,v2,v3,...) NOTE: use the special value NULL for id columns INSERT INTO table VALUES (NULL,v1,v2,v3,...)
SQL DELETE DELETE FROM table WHERE conditions NOTE: DANGEROUS!
SQL Gotchas quote text values do NOT quote number values always specify table links separate using commas FORMAT WELL!!
SQL Manual http://dev.mysql.com/doc/refman/5.0/en/

Weitere ähnliche Inhalte

Was ist angesagt?

Ms access tutorial
Ms access tutorialMs access tutorial
Ms access tutorialminga48
 
Access 2007-Datasheets 1-Create a table by entering data
Access 2007-Datasheets 1-Create a table by entering dataAccess 2007-Datasheets 1-Create a table by entering data
Access 2007-Datasheets 1-Create a table by entering dataOklahoma Dept. Mental Health
 
L4 working with tables and data
L4 working with tables and dataL4 working with tables and data
L4 working with tables and dataBryan Corpuz
 
Intro To DataBase
Intro To DataBaseIntro To DataBase
Intro To DataBaseDevMix
 
Access presentation
Access presentationAccess presentation
Access presentationDUSPviz
 
Training MS Access 2007
Training MS Access 2007Training MS Access 2007
Training MS Access 2007crespoje
 
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLESDATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLESNathRam2
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft AccessDUSPviz
 
Data Mining with MS Access
Data Mining with MS AccessData Mining with MS Access
Data Mining with MS AccessDhatri Jain
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 
Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema GajjarReema Gajjar
 

Was ist angesagt? (18)

Ms access tutorial
Ms access tutorialMs access tutorial
Ms access tutorial
 
Access 2007-Datasheets 1-Create a table by entering data
Access 2007-Datasheets 1-Create a table by entering dataAccess 2007-Datasheets 1-Create a table by entering data
Access 2007-Datasheets 1-Create a table by entering data
 
L4 working with tables and data
L4 working with tables and dataL4 working with tables and data
L4 working with tables and data
 
Intro To DataBase
Intro To DataBaseIntro To DataBase
Intro To DataBase
 
Access presentation
Access presentationAccess presentation
Access presentation
 
Training MS Access 2007
Training MS Access 2007Training MS Access 2007
Training MS Access 2007
 
Database intro
Database introDatabase intro
Database intro
 
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLESDATABASE CONCEPTS AND PRACTICAL EXAMPLES
DATABASE CONCEPTS AND PRACTICAL EXAMPLES
 
Sql basics
Sql basicsSql basics
Sql basics
 
Introduction - Database (MS Access)
Introduction - Database (MS Access)Introduction - Database (MS Access)
Introduction - Database (MS Access)
 
Access 2010
Access 2010Access 2010
Access 2010
 
Intro to Microsoft Access
Intro to Microsoft AccessIntro to Microsoft Access
Intro to Microsoft Access
 
Data Mining with MS Access
Data Mining with MS AccessData Mining with MS Access
Data Mining with MS Access
 
Mdst 3559-02-24-sql2
Mdst 3559-02-24-sql2Mdst 3559-02-24-sql2
Mdst 3559-02-24-sql2
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Entities and attributes
Entities and attributesEntities and attributes
Entities and attributes
 
Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema Gajjar
 
Chapter 4 Structured Query Language
Chapter 4 Structured Query LanguageChapter 4 Structured Query Language
Chapter 4 Structured Query Language
 

Andere mochten auch

Introduction to Project Management
Introduction to Project ManagementIntroduction to Project Management
Introduction to Project Managementcwarren
 
Requirements and Specifications
Requirements and SpecificationsRequirements and Specifications
Requirements and Specificationscwarren
 
Lecture Capture Discussion
Lecture Capture DiscussionLecture Capture Discussion
Lecture Capture Discussioncwarren
 
Web Project Management for Small Projects
Web Project Management for Small ProjectsWeb Project Management for Small Projects
Web Project Management for Small Projectscwarren
 
Lecture,discussion, inductive and deductive
Lecture,discussion, inductive and deductiveLecture,discussion, inductive and deductive
Lecture,discussion, inductive and deductiveShynie Abraham
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 

Andere mochten auch (9)

Introduction to Project Management
Introduction to Project ManagementIntroduction to Project Management
Introduction to Project Management
 
ZON Design Binder
ZON Design BinderZON Design Binder
ZON Design Binder
 
Faculty presentation
Faculty presentationFaculty presentation
Faculty presentation
 
Requirements and Specifications
Requirements and SpecificationsRequirements and Specifications
Requirements and Specifications
 
Lecture Capture Discussion
Lecture Capture DiscussionLecture Capture Discussion
Lecture Capture Discussion
 
Web Project Management for Small Projects
Web Project Management for Small ProjectsWeb Project Management for Small Projects
Web Project Management for Small Projects
 
Lecture,discussion, inductive and deductive
Lecture,discussion, inductive and deductiveLecture,discussion, inductive and deductive
Lecture,discussion, inductive and deductive
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Ähnlich wie Quick And Dirty Databases

Ähnlich wie Quick And Dirty Databases (20)

T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
Sql
SqlSql
Sql
 
Database
DatabaseDatabase
Database
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Oracle 11g SQL Overview
Oracle 11g SQL OverviewOracle 11g SQL Overview
Oracle 11g SQL Overview
 
PO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - SqlPO WER - Piotr Mariat - Sql
PO WER - Piotr Mariat - Sql
 
SQL2.pptx
SQL2.pptxSQL2.pptx
SQL2.pptx
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Database Application for La Salle
Database Application for La SalleDatabase Application for La Salle
Database Application for La Salle
 
Ms sql server tips 1 0
Ms sql server tips 1 0Ms sql server tips 1 0
Ms sql server tips 1 0
 
PDI data vault framework #pcmams 2012
PDI data vault framework #pcmams 2012PDI data vault framework #pcmams 2012
PDI data vault framework #pcmams 2012
 
Presentation pdi data_vault_framework_meetup2012
Presentation pdi data_vault_framework_meetup2012Presentation pdi data_vault_framework_meetup2012
Presentation pdi data_vault_framework_meetup2012
 
GROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptxGROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptx
 
Introduction to SQL..pdf
Introduction to SQL..pdfIntroduction to SQL..pdf
Introduction to SQL..pdf
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 
lovely
lovelylovely
lovely
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 

Kürzlich hochgeladen

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 

Kürzlich hochgeladen (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

Quick And Dirty Databases

  • 1. Quick and Dirty Databases(and SQL) Chris Warren cwarren@williams.edu x4323 Jesup 312
  • 2. Data Organization in Databases field (a.k.a. column) a bunch of fields make a record (a.k.a. row) a bunch of records make a table a bunch of tables make a database a bunch of databases make a DB system
  • 3. Designing a (Relational) DB Entities and Entity Relationships (ERD) Normalizing Detailing Cleanup
  • 4. Entities and Entity Relationships Entities (tables) ID (a.k.a. primary key) Entity Attributes (fields) Relationships 1-to-1 1-to-many or many-to-1 many-to-many
  • 5. Relationships 1-to-1 usually data is in the same table 1-to-many and many-to-1 foreign key goes with the many entity many-to-many linking table with 2 foreign keys, one for each side
  • 6. Create an ERD ERD = Entity Relationship Diagram Draw on paper Entities (tables) Relationships between them indicate type : 1-to-1, 1-to-many, many-to-many
  • 7. Detail the ERD Finalize table names and list fields table name should be plural primary id is singular + _id add any foreign keys list fields include unit in name add is_ or flag_ or _flag for true/false fields
  • 8. Normalizing Normalizing is basically removing duplication merge mostly similar tables split out common field sets split out conceptually distinct field sets
  • 9. Normalizing – Merge Tables tables have very similar field sets entities are both / all examples of a more general concept generalize the table name add a type field change foreign keys in other tables to include the type
  • 10. Normalizing – Split Out Field Sets same list of field repeated in different tables group of fields describes a distinct concept create a new table for that new entity add a foreign key to the new table in each of the original tables
  • 11. Normalizing – Split Out Concepts a table has multiple sub-parts common field name prefix is one indicator data would be repeated for many records create a new table for those fields add a foreign key to the original table
  • 12. ERD Detailing create any grouping tables as needed add data types and descriptions to fields int varchar (string up to 255 characters) text (BIG string) date and/or time boolean (true/false)
  • 13. ERD Cleanup add timestamps (created_at, updated_at) review relationships, fix as needed review fields, add any missing characteristics
  • 14. ERD is DONE! Now you get to implement it...
  • 15. SQL – Structured Query Language used to send commands to a database there’s a core standard, and a lot of vendor-specific minor changes / additions two branches data definition – create tables data manipulation – add, edit, retrieve, delete data http://dev.mysql.com/doc/refman/5.0/en/
  • 16. SQL concepts (manipulation) Databases are a big pile of information Identify which piece of info you want to manipulate State how you want to manipulate it retrieve it edit it delete it add it
  • 17. Writing SQL build it backwards.... what you want to do select, update, delete, or insert where it is the table and row(s) the specific parts the fields
  • 18. SQL Conventions SQL keywords in upper case Your info (tables, fields, etc) in lower case Indent each section of the statement Use multiple lines
  • 19. SQL SELECT (most common) 3.the SELECT clause – which fields SELECT fields FROM tables WHERE conditions GROUP BY non-aggregate fields ORDER BY fields 1.the FROM clause – which tables 2.the WHERE clause – which rows
  • 20. SQL SELECT Example SELECT e.name FROM cwarren_equipment AS e ,cwarren_location AS l WHERE e.location_id=l.location_id AND l.name=‘Lab 54’;
  • 21. SQL SELECT Example SELECT e.name FROM cwarren_equipment AS e JOIN cwarren_location AS l ON e.location_id=l.location_id WHERE l.name=‘Lab 54’;
  • 22. SQL UPDATE UPDATE TABLE table SET field1=newval1 ,field2=newval2,... WHERE conditions
  • 23. SQL INSERT INSERT INTO table VALUES (v1,v2,v3,...) NOTE: use the special value NULL for id columns INSERT INTO table VALUES (NULL,v1,v2,v3,...)
  • 24. SQL DELETE DELETE FROM table WHERE conditions NOTE: DANGEROUS!
  • 25. SQL Gotchas quote text values do NOT quote number values always specify table links separate using commas FORMAT WELL!!