(a) SQLite3:
(1) Definition: A lightweight, embedded database. is an in-process library, which is essentially a file, does not need to rely on the external, does not need the server, does not need to install or manage, is a single disk file. Server-side databases tend to be large, such as Orcal,mysql,sql server, which requires separate servers, installation configurations, and a large number of people to maintain.
(2) Data type: Five data type, integer integer, real decimal, text string, blob binary data (put a picture, audio, video plug in, generally not plug, database is query retrieval, not saved, unable to retrieve, general value of the path), NULL.
(3) Primary key: Primary key: Uniquely identifies a record, usually an integer, which is usually automatically increased. Each table stores the same type of data. For example, a dog object, each row is an object, and each column is a property of the object. such as Age,name and so on.
(4) The server will have an exclusive lock when it is saved. Because there may be multiple simultaneous storage. To uniquely differentiate the ID, the server locks itself into the next record. And the ID primary key is uniquely marked and is automatically generated by the database. And occasionally, the primary key can be used in other ways.
(5) So, SQL3 is the storage of data, a table can be an object, the different tables can also (generally inevitable) have a relationship. iOS development generally needs to understand the database code, such as the navicat automatically generated a table, if written in database code, this is the case.
-- Create datasheet table if not exists "T_person" (//create a table if it does not exist "ID " integer not null primary key AutoIncrement,//ID integer type does not automatically grow for null primary key "name" text ,//Name text type "Age" integer ,//ages INTEGER Type "height" real//Height REAL type )
(6) Data modification: A T_person table has been created above, and there are four properties, then the data can now be inserted.
6.1 Increase:
INSERT into VALUES ('shy',+,1.7)//insert a data data into the T_person table
The field properties of SQL are actually only for programmers to see, in fact, anything can be saved. And did not do calibration, you give an int to save the string is all right-. -! But it turns out that SQL3 is the only choice for mobile-embedded development. Inserting 10,000 pieces of data also takes 0. A few seconds, very fast performance is very good.
INSERT into VALUES ('shy','+ ','shy')// Insert an error data type and the database table is unaffected by any
6.2 Change: Must set the condition when updating the data, because the SQL is unable command+z return, the data changes cannot change.
UPDATE SET = ' aixin ' = - = the WHERE = 2
Now the data is changed.
6.3 Delete: The deletion of data should also pay attention to set conditions, or the entire table will be gone ... You'll be fired.
DELETE from T_person WHERE = 1;
Note: the '; ' semicolon indicates the end of a complete event, which can be added or not added (modified, deleted), but with a more formal SQL statement. If the delete condition is not met, then nothing will happen.
To delete an entire table:
DROP TABLE T_person;
6.4 Check:
SELECT * fromT_person; Query the entire table all information, development generally do not, adjust the trial, because there is no control to choose whatSELECTName,age fromT_person;//Query specific propertiesSELECT Count(*) fromT_person;//Query How manySELECT Count(*) fromT_personWHEREAge< -;//Conditional selection query how manySELECTName,age,height fromT_personWHEREAge< -; Conditions Show specific properties
SELECT Max(age) fromT_person;//query Maximum ageSELECT min(age) fromT_person;//query Minimum ageSELECTId,name,age fromT_person//Query 3 limit3;SELECTId,name,age fromT_person//from. Location query: Bar Limit3,3;SELECTId,name,age fromT_person//From ID: Location query: StripWHEREId> 5LIMIT2;
SELECT from T_person//Sort by name, default a ascending ORDER by name; SELECT from T_person//desc is descending, and if the name is the same as the second requirement, age is sorted in ascending order ORDER by DESC ASC;
SQLite3 and iOS localized storage