zoukankan      html  css  js  c++  java
  • iOS数据库学习(2)-基础SQL语句

    /* 1. 创建一个数据表 */
    CREATE TABLE IF NOT EXISTS t_dog (name text, age integer);
    CREATE TABLE IF NOT EXISTS t_cat (name,age);
    CREATE TABLE IF NOT EXISTS t_student (name text NOT NULL, age integer);
    CREATE TABLE IF NOT EXISTS t_student (name text NOT NULL UNIQUE, age integer NOT NULL);
    CREATE TABLE IF NOT EXISTS t_student (name text, age integer DEFAULT 1); /* 指定年龄默认为1 */
    CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text, age integer); /* SQLite中AUTOINCREMENT可以省略 */
    
    
    /* 2. 删除表 */
    DROP TABLE 表名
    DROP TABLE IF EXISTS 表名
    
    /* 3. 插入数据 */
    INSERT INTO t_user (username,age,height) VALUES (‘赵六’,20,1.90);
    INSERT INTO t_user(username,age) VALUES(‘陈七’,21);
    
    /* 4. 更新数据 */
    UPDATE t_user SET height = 1.65, age = 14;
    UPDATE t_user SET left_count = 0 WHERE price < 1000;
    
    /* 5. 删除数据 */
    DELETE FROM t_user 
    DELETE FROM t_shop WHERE left_count = 0;
    DELETE FROM t_shop WHERE left_count < 500 AND price < 2000;
    DELETE FROM t_shop WHERE left_count < 500 OR price < 2000;
    
    /* 6.查询数据 */
    SELECT name,price FROM t_shop;
    SELECT * FROM t_shop;
    SELECT * FROM t_shop left_count > 800;
    SELECT * FROM name shop_name, price AS shop_price, left_count 库存 FROM t_shop s;
    SELECT s.name, price, s.left_count FROM t_shop s;
    SELECT count(name) FROM t_shop;
    SELECT count(name) FROM t_shop WHERE left_count > 800;
    SELECT count(*) FROM t_shop;
    SELECT count(*) 剩余数量 FROM t_shop;
    SELECT * FROM t_shop ORDER BY left_count ASC;
    SELECT * FROM t_shop ORDER BY left_count DESC, price ASC;
    SELECT * FROM t_shop LIMIT 4,8;
    SELECT * FROM t_shop ORDER BY price DESC LIMIT 0,10;
    SELECT * FROM t_shop LIMIT 7 /* 等价于LIMIT 0,7 */
  • 相关阅读:
    Python基础学习九 数据库备份
    Python基础学习八 写日志
    Python 小练习三 发邮件
    Python基础补充(二) 多核CPU上python多线程并行的一个假象【转】
    pat 1118 Birds in Forest (25分) 并查集
    Java Map实现按value从大到小排序
    java实现排列组合(通俗易懂)
    java实现24点游戏代码
    eclipse搭建struts2环境及所遇到的问题
    java非常好用的读取文件的流的代码
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6184910.html
Copyright © 2011-2022 走看看