Click here to load reader
Jun 20, 2015
2. Key topics / learning outcomesof this lecture Database use within an Android App; Learn the concept of creating anSQLite Database; A look at SQL (Structured QueryLanguage);2 3. What is a database?B4004A L1 3 4. Different types of DatabaseB4004A L1 4 5. Android DatabaseThe database used with Android is calledSQLite.This database is a trimmed downversion of MySQL, PostgreSQL andother similar databases.B4004A L1 5 6. SqLite Android Database it is a relational database; SQLite was originally designed for defence purposes; it has no administrator; it uses less data types than other typical relationaldatabases: int: a signed integer; real: a floating-point number; text: a text string; blob: a blob of data; It is shipped with Android: Each APP has its own SQLite database.B4004A L1 6 7. Usual steps to design a database Create a Data dictionary List all the data terms, example: name, address, postcode; Allocate a data type to the field example: the _id field has a data type of int; Create an Input/Output list identify all inputs and outputs, example: input name, address, postcode example: output list of all address in postcode W1.B4004A L1 7 8. Usual steps to design a database Identify Entities list relationships one to one one to many many to many List attributes their data type; their default value; Normalize reduce duplication of data storage create new tables to reduce duplication of fields; Add keys primary key foreign keysB4004A L1 8 9. Data Flow Diagrams Once all the information gathering is complete, adatabase design is moved on to the drawingstage; The first drawing will be very concise, almost likea birds eye view of the database, usually nameda Context drawing; Each section of the Context drawing will beexpanded level by level until the detail isexhausted, therefore no more detailed level maybe reached.B4004A L1 9 10. Context DrawingB4004A L1 10 11. An Example of a Data Flow DiagramSource: http://conta11.my3gb.com/examlpe-of-data-flow-diagram.htmlB4004A L1 11 12. An example of database tablestogether with their relationshipsSource: http://carlibrary.org/CarDatabases.htmB4004A L1 12 13. Databases comprise of Tables Usually a database will contain more than onetable: example PERSON, PERSON_ADDRESS. Fields Fields are table columns with a heading andcolumn content Records are table rows with an id and row contentB4004A L1 13 14. a closer look at databases B4004A L1 14 15. A table within a Database_id Name Password1 Pearson 1232 John abcd3 Viz 5678This table willhave a name,for example:PERSONB4004A L1 15This databasewill have aname, forexample:ADDRESS_BOOK 16. Relational Tablesaddress_id Address _id1 1 Smith Street 22 80 Strand 13 6 Jones Square 3_id Name Password1 Pearson 1232 John abcd3 Viz 5678This table willhave a name,for example:PERSONB4004A L1 16This table willhave a name, forexample:PERSON_ADDRESS 17. Relational Tablesaddress_idAddress Address_Type _id1 1 Smith Street Halls of Residence 22 80 Strand Office 13 6 Jones Square Private Rented 34 2 The Farmhouse Home 2_id Name Password1 Pearson 1232 John abcd3 Viz 5678This table willhave a name,for example:PERSONB4004A L1 17This table willhave a name, forexample:PERSON_ADDRESS 18. Relational Tablesaddress_idAddress Address_Type _id1 1 Smith Street Halls of Residence 22 80 Strand Office 13 6 Jones Square Private Rented 34 2 The Farmhouse Home 2_id Name Password1 Pearson 1232 John abcd3 Viz 5678ForeignKeyB4004A L1 18PrimaryKeyFields(Columns)Records(Rows) 19. Use SQL to access data, for exampleSQL SyntaxSELECT * FROM PERSON INNER JOIN PERSON_ADDRESS ON PERSON._id =PERSON_ADDRESS._id WHERE PERSON.Name=John;B4004A L1 19SELECT column_name(s)FROM table1INNER JOIN table2ON table1.column_name=table2.column_nameWHERE table1.column_name= ? ;Actual SQL derived from the syntax 20. More SQL (Structured QueryLanguage) Resources SQL is a standard database protocol: adopted by most relational databases; Provides syntax for interaction with databases; For more info, visit W3schools for theirtutorial on SQL: here you will find all the SQL syntax needed tointeract with your database.http://www.w3schools.com/sqlB4004A L1 20 21. Seminar In the seminar for this lecture, you will becopying and pasting code into IntelliJ andrunning a database. You will be making some changes to the fieldsand tables to learn how you may tailor thedatabase to suit a different application.B4004A L1 21 22. Workshop In the workshop for this lecture, you will beviewing a series of tutorials explaining moreabout SQLite.B4004A L1 22 23. Essential work for next week Please consult the OLE for details of: Essential readings* Seminar/workshop preparation work* Recommended further readings Any additional learning* Essential readings and preparation work must always be completed in timefor the next session23 24. End of presentation Pearson College 2013