• Sqlite3笔记


    .tables 查看表
    .databases 创建数据库
    alter table 表名 RENAME TO 新表名
    ALTER TABLE 表名 add column 列名 datatype [DEFAULT expr]
    .schema user 查看user表的列项
    drop table 表名 删除表


    CREATE TABLE emloyees(
    Id INTEGER not null,
    name TEXT,
    sex INTEGER,
    birthday INTEGER,
    entry_date INTEGER,
    job TEXT,
    salary REAL,
    resume TEXT
    )

    CREATE TABLE p(
    Id INTEGER not null,
    name TEXT
    )

    删除user表job列
    步骤:
    1.新建临时表(t)
    CREATE TABLE t(
    Id INTEGER not null,
    name TEXT,
    sex INTEGER,
    birthday INTEGER,
    entry_date INTEGER,
    salary REAL,
    resume TEXT
    )

    2.将user表中的数据读入t表 :create table t as select Id,name,sex,birthday,entry_date,salary,resume from user;
    3.删除user表、
    4.将t表重命名为user表

    insert into tableName [(column1,column2,...)] values (数据) 插入数据
    update tableName set colName1 = value1 [where clomeName = value]; 修改数据
    delete from tableName where column = value,.. 删除数据
    select [DISTINCT] *|colmun1 as columnC,colmun2... from table where ... order by 查询数据
    asc 是升序 desc是降序

    select count(*|colmun) from tableName 统计不为null的条目数
    select sum(column1),sum() from tableName 统计总和
    select max() from tableName 最大值
    select avg() from tableName 平均值

    select column from tableName group by column; 分组
    select column from tableName group by column having 筛选


    一般约束
    CREATE TABLE p(
    Id INTEGER unique, //唯一
    Id1 INTEGER not null, //不为空
    Id2 INTEGER check(Id2 > 0), //
    Id3 INTEGER defalut 1, //默认值1
    name TEXT
    )

    主键约束
    create table t(
    id integer primary key autoincrement,
    name text
    );

    外键约束
    create table s(
    teacher integer,
    foreign key(teacher) references t(id)
    );

    pragma foreign_keys=on; 开启外键通过

    union 联合查询

    limit length offet num 跳过num个取length个 简写为limit length,offset

     

  • 相关阅读:
    【刷题】Linux修改权限命令
    【刷题】Linux进程通信方式
    【刷题】网络:TCP与UDP
    【刷题】SQL基本操作
    【刷题】数据库三大范式
    【刷题】java会不会内存泄漏
    【刷题】Java-重写和重载
    【刷题】Java面向对象概述
    【刷题】Java垃圾回收常见问题
    测试常见问题合集
  • 原文地址:https://www.cnblogs.com/huangshiyu13/p/4802321.html
Copyright © 2020-2023  润新知