Sqlite study notes 5: insert data, query data and delete data, sqlite Study Notes

Source: Internet
Author: User

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 (...)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.