Date post: | 22-Feb-2017 |
Category: |
Data & Analytics |
Upload: | sacheen-dhanjie |
View: | 91 times |
Download: | 0 times |
DatabasesSACHEEN DHANJIE
Sacheen DhanjieSenior Developer @ Afrihost.com
What are databases?•A structured set of data held on a computer
•A place to store data for reading and writing and updating.
Types of databases• Relational Databases• Document Oriented Databases• Distributed Databases• Key Value Databases• There are many other types of databases, you can read up on them here: https://en.wikipedia.org/wiki/Category:Types_of_databases
Relational Database• Relational Databases as databases that allow data tables to be related in some manner.
• This allows for data integrity• Normalization• Relationships
Normalization• Normalization is the process of organizing the columns (attributes) and tables (relations) of a relational database to minimize data redundancy.
• Basically it means, we take a table that has many columns and split it up into smaller tables with little or no redundancy.
• Smaller organized tables also improves performance and disk space usage.
Normalization
Normalization
What else needs to be done?
Normalization
Relationships
Relationships• How would we connect these two table?
Relationships
Relationships
Relationship Type• One to Many
• One Client has Many Client Products • One to One
• One Stock Item belongs to One Client• Many to Many
• Many Users have Many Permissions• http://www.techrepublic.com/article/relational-databases-defining-relationships-between-database-tables/
Keys
Keys• Primary Key
• Uniquely identifies a record• Joint Key
• Two or more columns that uniquely identifies a record• Indexes
• Improves queries to the database• Useful on large tables• index columns that will be used when querying the database
• Foreign Keys• Theses are used when creating relationships between tables
Select
CRUD – Create/ Read / Update / Delete
Joining Tables
Joins
• Left Join• Inner Join• Outer Join• UnionSub Query [select from a select] => expensivehttp://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.htmlhttp://www.mysqltutorial.org/
Transactions
Transactions
START TRANSACTION – initiates the transactionCOMMIT – save everything in the transactionROLLBACK – revert all the changes
Features• Triggers
• MySQL triggers are stored programs that are executed automatically to respond to specific events associated with table e.g., insert, update or delete a record
• Stored Procedures• SQL wrapped in a callable function
• getUsers() = select * from Users;• CALL getUsers()
NoSQL Databases• Databases that stores information in Collections• A Collection has Documents• A Document has an Objects• Most do not support transactions• Used to store dynamic information
• GEO location data
NoSQL Databases• MongoDB• CounchDB• neDB
NoSQL Databases• db.items.find({}).pretty()
Key Value Pair Databases• Redis• Riak• Key value databases are great for caching information• http://nosql-database.org/
Questions?