sqlite(4)-insert语句

语法##

INSERT INTO TABLE_NAME(column1, column2, column3, … columnN) VALUES(value1, value2, value3, …valueN)

如果插入所有的项

INSERT INTO TABLE_NAME VALUES(value1, value2, value3, …valueN);

实例##

CREATE TABLE COMPLANY(
ID INT PRIMARY KEY NOT NULL,
NAME INT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);

现在,下面的语句将在COMPANY表中创建六个记录

INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, ‘Paul’, 32, ‘California’, 20000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, ‘Allen’, 25, ‘Texas’, 15000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, ‘Teddy’, 23, ‘Norway’, 20000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (4, ‘Mark’, 25, ‘Rich-Mond ‘, 65000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (5, ‘David’, 27, ‘Texas’, 85000.00 );
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (6, ‘Kim’, 22, ‘South-Hall’, 45000.00 );

也可以使用第二种语法在COMPANY表中创建一个记录

INSERT INTO COMPANY VALUES(7, ‘James’, 24, ‘Houston’, 100000.99);

IDNAMEAGEADDRESSSALARY
1Paul32California20000.0
2Allen25Texas15000.0
3Teddy23Norway20000.0
4Mark25Rich-Mond65000.0
5David27Texas85000.0
6Kim22South-Hall45000.0
7James24Houston10000.0

使用一个表来填充另一个表##

INSERT INTO first_table_name [(column1, column2, .. columnN)]
SELECT column1, column2, … columnN
FROM second_table_name
[WHERE codition];

    原文作者:Flannery
    原文地址: https://www.jianshu.com/p/9c6dff2c11d2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞