Sqlite3 operations in iOS
Statement: I have not used all of the following commands. They are only used for favorites. You are welcome to point out the error 'select count (*) FROM sqlite_master WHERE type = "table" AND name = "table_name" // query the number of tables named "table_name" FROM the sqlite_master system table. Yes, it is the number. Therefore, if the result is greater than 0, 'select name, SQL FROM sqlite_master WHERE type = "table" AND name = "table_name" // This statement is said to return the statement for creating "table_name". Yes, it is a statement, of course, each field name of "table_name" is included.
Select * from "table_name", [rs columnNameForIndex: I] // rs is the returned result set. This statement returns the field name with index = I, is the field name create table "table_name" (first_col integer) // CREATE a data TABLE; create table "table_name" (first_col integer DEFAULT 0, second_col varchar DEFAULT 'hello') // CREATE a data TABLE, the first_col field has the default value; 1) attach database 'd:/mydb. db AS mydb // The current link is "d:/mydb. db "database, subsequent operations will take effect under this database 2 ). exit // exit the current database;
Create table if not exists "table_name" (first_col integer) // IF the created "table_name" already EXISTS, a conflict will occur, leading to statement execution failure. if not exists can avoid this error;
Create table "table_name2" as select * FROM "table_name1"; // This statement creates table_name2 in table_name1 mode, excluding primary key constraints and default values. schema "table_name2" returns the statement for creating a data table;
Create table "table_name" (first_col integer primary key asc); // CREATE a data TABLE that contains progressive constraints;
Create table "table_name" (first_col integer UNIQUE); // CREATE a TABLE that contains the uniqueness constraint of field values;
Create table "table_name" (first_col integer not null); // CREATE a TABLE with the constraint that the field value cannot be NULL;
Create table "table_name" (first_col integer CHECK (first_col <5); // CREATE a TABLE that contains field value range constraints;
Alter table "table_name1" rename to "table_name2"; // modify the name of TABLE "table_name1" TO "table_name2"
Alter table "table_name" add column second_col integer; // ADD the field second_col to the "table_name" TABLE.
Drop table "table_name"; // delete a data TABLE "table_name"
Drop table if exists "table_name"; // an error occurs when you delete a data TABLE that does not exist. Therefore, if exists is used to avoid errors;
Create view "table_name" as select * FROM "table_name" WHERE first_col> 100; // CREATE a VIEW
Drop view if exists "view_name"; // delete a VIEW