SlideShare a Scribd company logo
1 of 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/

More Related Content

What's hot

Ms access tutorial
Ms access tutorialMs access tutorial
Ms access tutorial
minga48
 
Access presentation
Access presentationAccess presentation
Access presentation
DUSPviz
 
Data Mining with MS Access
Data Mining with MS AccessData Mining with MS Access
Data Mining with MS Access
Dhatri Jain
 

What's hot (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
 

Viewers also liked

Viewers also liked (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
 

Similar to Quick And Dirty Databases

Similar to 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
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
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
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
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
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).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...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
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.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 

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!!