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 */
  • 相关阅读:
    Vue2 后台管理系统解决方案
    vuejs 和 element 搭建的一个后台管理界面
    Composer 是什么
    解决无限 This file is indented with tabs instead of 4 spaces
    (七)boost库之单例类
    (六)boost库之内存管理shared_ptr
    (五)boost库之随机数random
    (四)boost库之正则表达式regex
    (二)boost库之字符串格式化
    (一)boost库之日期、时间
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6184910.html
Copyright © 2011-2022 走看看