![]() The tables in a database and the columns in each table are collectively known as the schema. The following table maps common Kotlin data types to their SQLite equivalents. SQLite databases use data types too! Data table columns must have a specific data type. In Kotlin, you're familiar with data types like Int and Boolean. Examples of NoSQL databases include Redis or Cloud Firestore. Other kinds of databases, known as NoSQL, are structured similarly to a JSON object with nested pairs of keys and values. Note: Not all databases are organized into tables, columns, and rows. ![]() SQL is simply a way to add and retrieve data from a relational database with a few lines of code. You won't have to learn C or any entirely new programming language to work with a relational database. Specifically, SQLite refers to a lightweight C library for relational database management with Structured Query Language, known as SQL and sometimes pronounced as "sequel" for short. SQLite is a commonly used relational database. ![]() For the example above, that means you name the tables teacher, student, and course, not the plural forms of teachers, students, and courses. Note: Like with Kotlin classes, the convention is to use the singular form for the name of database tables. ![]() The presence of a foreign key means there's a relationship between the tables. When a table references the primary key of another table, it is known as a foreign key. This identifier is known as the primary key. For example, a graduate student might have a single professor as a doctoral advisor whereas that professor is the doctoral advisor for multiple students.Įvery table in a relational database contains a unique identifier for rows, such as a column where the value in each row is an automatically incremented integer. A database is called a relational database when it can model relationships between tables. Just as a spreadsheet can contain multiple sheets and an app can contain multiple classes, a database can contain multiple tables. Objects contain values for each property defined in the class, just as rows contain values for each column defined in the data table. Objects, like rows, are the actual data.Properties, like columns, define the specific pieces of data that every instance of the class should contain.Classes, like tables, model the data you want to represent in your app.The structure of a relational database also mirrors what you already know about classes and objects in Kotlin. Rows contain the actual data that consist of values for each column in the table.Columns define the data that each row in the table contains.Tables define high-level groupings of data you want to represent, such as students and professors.For example, you might define columns for a student's ID, name, major, and grade.Įach row contains data for a single student, with values for each of the columns.Ī relational database works the same way. If you are familiar with a spreadsheet program like Google Sheets, you are already familiar with a basic analogy for a database.Ī spreadsheet consists of separate data tables, or individual spreadsheets in the same workbook.Įach table consists of columns that define what the data represents and rows that represent individual items with values for each column. To learn more about the different methods for storing data on Android, refer to the Data and file storage overview. This unit discusses Room and Preferences Datastore. Note: Android apps have a number of ways to store data, including both internal and external storage. This codelab teaches the fundamentals of SQL-Structured Query Language-which, while not an actual programming language, provides a simple and flexible way to read and modify a SQLite database with just a few lines of code.Īfter you gain a fundamental knowledge of SQL, you'll be prepared to use the Room library to add persistence to your apps later in this unit. SQLite provides a relational database that allows you to represent data in a similar way to how you structure data with Kotlin classes. SQLite is a common way provided by the Android SDK for Android apps to persist data. Persistent data ensures user-generated content isn't lost when the app is closed, or data downloaded from the internet is saved so it doesn't need to be redownloaded later. The Clock app stores your recurring alarms, the Google Maps app saves a list of your recent searches, and the Contacts app lets you add, edit, and remove your contacts' information.ĭata persistence-storing or persisting data on the device-is a big part of Android development. Many of the apps you use store data directly on the device.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |