Notes on SQLite for table creation to be used in the Android app
Because it uses SQLite in Android, I want to create a table, and notes, Is it a rule when creating a table?
With Android, you can use the relational database called SQLite.
To save the data, you must first create a table.
Be determined at the time of table creation, as a side note, is not particularly as a specification of the SQLite.
However, when you are using a class of relations SQLite, which is provided by Android, may have been implemented as the assumption that, in order to take advantage of the classes of them, according to the rules it is assumed that must be placed.
Below is the rule.
To define the column ID
Also referred to as "column" "field" and "column".
"ID" and, for each record, is that the number and a unique number.
What descriptive speaking duplicate ID in one table, and no.
In addition, this column name ID, do the following.
_id
Class of Android's SQLite relationship, there is a class that is implemented on the assumption that there is a "_id" column to indicate this ID.
For example, such as CursorAdapter.
Therefore, when using SQLite in Android apps, SQL to create a table (. Also known as queries), you have to like the following form.
create table table name (_id integer primary key autoincrement, · · ·)
_id column 1, 2, 3, since it is stored and · · ·, The type is integer.
Also, ID is a unique number, so duplication is prohibited, and give it a primary key.
And "autoincrement" is an indication that literally, that is incremented automatically.
Insert the record at times, even after Insert column without specifying the value of _id, look at the records of the table at that point in time, you will see numbering automatically.
If you as a specific example, and want to make a table to store the bookmark so that it looks something like the following.
create table bookmarklist
(_id Integer primary kye autoincrement, url text not null)
not null, it put NULL value is I can not! That is specified.
If you try to put a NULL, will result in an error.
Also, when inserting a record is as follows.
insert into bookmarklist (url)
values ('http://android.roof-balcony.com')
By the way,
In the insert statement, (immediately after the table name, the part before the values) to insert the column name can be omitted.
However, since the fall readability when viewed from the later, let you specify without abbreviation.
As you'll see with a single column called, "url" and that the above sample, and this URL is stored, I do not know and does not examine the definition of the table and have been omitted.
You can also supposed to be also at times such as at a later, to add or remove columns to the table, and are omitted from the column names to be inserted into the data they entered the column and was intended for a different The.
This is not limited to the Android, is like a general implicit rules of SQL.











