Meeting notes, including challenges:
What is a database?
- Way to store data
- Consists of Tables - like Excel sheets
- We use relational databases
Technologies / Tools
- Databases: MySQL / MS SQL Server / Oracle
- Integrating: PHP, AMFPHP, FlashRemoting
- vs. Excel
- vs. Access / FileMaker
- Terminal, GUIs
- DB Design Tool - Eclipse with Clay Database Modeling UI
When use database?
- Lots of data
- Need to save data
- Need to share data across users
Database Design- Facebook Example
- Identify structure of your data
- set up tables for items
- fields (columns)
- datatypes - int, char, varchar, text, bit, etc...
- primary key
- auto increment
- create relationships - primary key / foreign key
- 1 to many
- many to many
- Nomalization
Working with the Data - Facebook Example
Challenges:
- Get all users
- Order by first name
- Order by first name then last name
- Get all 'Matthews'
- Get all with a first name that begins with 'M'
- Get all with a first name or last name that begins with 'M'
- Update a user
- Insert a user
- Quizzes
- Get all Quizzes
- Get all Quiz Questions
- Get all Quiz Question Answers
- Get all Quiz Question Answers for an Individual
- Interests
- Users and their Interests
- Get all users with similar interests
- Games
- Get all high scores
- Generate a high score list with just the top scores for each game
- Friends
- Get a user's friends
URLs
Challenge Answers
- Get all users - SELECT * FROM user
- Order by first name - SELECT * FROM user ORDER BY firstName
- Order by first name then last name - SELECT * FROM user ORDER BY firstName, lastName
- Get all 'Matthews' - SELECT * FROM user WHERE firstName = 'Matthew'
- Get all with a first name that begins with 'M' - SELECT * FROM user WHERE firstName LIKE 'M%'
- Get all with a first name or last name that begins with 'M' - SELECT * FROM user WHERE firstName LIKE 'M%' OR lastName LIKE 'M%'
- Get all with a first name or last name that begins with 'M', return only first name and last name - SELECT firstName, lastName FROM user WHERE firstName LIKE 'M%' OR lastName LIKE 'M%'
- Update a user - UPDATE user SET firstName = 'Michael' WHERE userID = 12
- Insert a user - INSERT INTO User (userID, userName, firstName, lastName) VALUES (NULL, 'garyg', 'Gary', 'Goldberger');
- Quizzes
- Get all Quizzes - SELECT * FROM quiz
- Get all Quiz Questions - SELECT * FROM quiz INNER JOIN quizQuestion on quiz.quizID = quizQuestion.quizID
- Get all Quiz Question Answers - SELECT * FROM Quiz INNER JOIN QuizQuestion on Quiz.quizID = QuizQuestion.quizID INNER JOIN QuestionAnswer ON QuizQuestion.quizQuestionID = QuestionAnswer.quizQuestionID
Better - SELECT * FROM Quiz q INNER JOIN QuizQuestion qq on q.quizID = qq.quizID INNER JOIN QuestionAnswer a ON qq.quizQuestionID = a.quizQuestionID ORDER BY q.quizID, qq.questionNumber, a.answerLetter - Get all Quiz Question Answers for an Individual - SELECT * FROM Quiz q INNER JOIN QuizQuestion qq on q.quizID = qq.quizID INNER JOIN QuestionAnswer a ON qq.quizQuestionID = a.quizQuestionID INNER JOIN UserAnswer UA ON UA.questionAnswerID = a.questionAnswerID INNER JOIN User u ON u.userID = ua.userID WHERE u.userName = 'briang' ORDER BY q.quizID, qq.questionNumber, a.answerLetter
- Interests
- Users and their Interests - SELECT * FROM User u INNER JOIN User_Interest_Linker uil ON u.userID = uil.userID INNER JOIN Interest i ON i.interestID = uil.interestID
- Get all users with similar interests - SELECT * FROM User_Interest_Linker uil INNER JOIN user u ON u.userID = uil.userID INNER JOIN interest i ON i.interestID = uil.interestID WHERE uil.interestID IN (SELECT i.interestID FROM User u INNER JOIN User_Interest_Linker uil ON u.userID = uil.userID INNER JOIN Interest i ON i.interestID = uil.interestID WHERE u.userName = 'briang') AND u.userName != 'briang'
- Games
- Get all high scores - SELECT * FROM user u INNER JOIN HighScore hs ON u.userID = hs.userID INNER JOIN Game g ON g.gameID =hs.gameID
- Generate a high score list with just the top scores for each game - SELECT g.name, u.firstName, u.lastName, max(hs.highScore) FROM user u INNER JOIN HighScore hs ON u.userID = hs.userID INNER JOIN Game g ON g.gameID =hs.gameID GROUP BY g.gameID
- Friends
- Get a user's friends - SELECT u2.firstName, u2.lastName FROM user u1 INNER JOIN Friend f on f.userID1 = u1.userID INNER JOIN user u2 ON f.userID2 = u2.userID WHERE u1.userName = 'briang' ORDER BY u2.firstname, u2.lastName
No comments:
Post a Comment