zoukankan      html  css  js  c++  java
  • 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

     

  • 相关阅读:
    Win7 64位下ProxyCap代理Java
    kafka一个诡异错误
    linux下oracle修改、新建用户并授权
    es常用查询
    linux 下启动tomcat报错 Cannot find ./catalina.sh
    linux虚拟机添加端口访问
    Linux下启动Oracle服务和监听程序
    es基础
    mysql授权远程任意人登录
    添加POI导出excel通用工具类
  • 原文地址:https://www.cnblogs.com/huangshiyu13/p/4802321.html
Copyright © 2011-2022 走看看