Sqlite study notes 5: insert data, query data and delete data, sqlite Study Notes
Zeng Wen: All programming is data-centric, which makes sense.
The so-called database has no data. Next we will look at how to insert data into the table.
1. Insert data
1. Create a table
To insert data, you must first create a table:
CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL);
2. Method 1: Specify Columns
There are two basic formats for data insertion. The first is to specify columns. The syntax is as follows:
INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN);
For example:
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)VALUES (1, 'hanfeng', 25, 'Hubei', 10000.00 );
The insert method only needs to assign the not null column to the specified value. other unspecified columns can be empty.
3. Method 2: complete Columns
The second insert method is to specify a value for each column rather than a column. Note that the order must be consistent.
INSERT INTO TABLE_NAME VALUES (value1, value2, value3,...valueN);
2. Data Query
1. query the specified Column
Query value the value of a specified column in a table:
SELECT column1, column2, columnN FROM table_name;
2. query the values of all columns in the table.
SELECT * FROM table_name;
3. Set the output format
. Header on -- display the listing. mode column -- set the column to its
3. delete data
Basic Syntax:
DELETE FROM table_nameWHERE [condition];
How does sqlite determine that the inserted data is the same as the data in the table?
Select the data before insertion. If yes, the data is not inserted. Or insert directly, because it has the same id, the insertion will fail and will not be inserted.
How to insert data into SQLite database tables?
Insert into thetable values (...)