Sqlite常用SQL语句 发表于 2015-06-27 | 分类于 DB | | 阅读量 次 本篇介绍Sqlite常用SQL语句写法. sqlite是很经典的微型数据库.使用非常方便.这里把常用操作整理一下,作个参考. 参考: 这篇SQL很多其他指令 create table SQLite Python Tutorial SQL操作: 增,删,改,查. 1. CREATE Table123456789101112131415161718格式:CREATE TABLE database_name.table_name( column1 datatype PRIMARY KEY(one or more columns), column2 datatype, column3 datatype, ..... columnN datatype,);示例:sqlite>CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL); 2. DROP Table123456格式:DROP TABLE database_name.table_name;示例:sqlite>.tables # 查看有哪些表sqlite>DROP TABLE COMPANY; # 删除表 3. INSERT Table1234567891011121314151617181920212223242526272829303132格式:方式1:INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] VALUES (value1, value2, value3,...valueN);方式2:INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);方式3:INSERT INTO first_table_name [(column1, column2, ... columnN)] SELECT column1, column2, ...columnN FROM second_table_name [WHERE condition]; 示例: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 ); 4. UPDATE Table123456789格式:UPDATE table_nameSET column1 = value1, column2 = value2...., columnN = valueNWHERE [condition];示例:qlite> UPDATE COMPANY SET ADDRESS = 'Texas' WHERE ID = 6;sqlite> UPDATE COMPANY SET ADDRESS = 'Texas', SALARY = 20000.00; 5. SELECT Table12345678910格式:方式1:SELECT column1, column2, columnN FROM table_name;方式2:SELECT * FROM table_name;示例:sqlite> SELECT ID, NAME, SALARY FROM COMPANY; 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏