zoukankan      html  css  js  c++  java
  • SQLite

    简介

    一种嵌入式数据库,它的数据库就是一个文件。由于SQLite本身是C写的,而且体积很小,所以,经常被集成到各种应用程序中
    
    • 创建数据库
    sqlite3 test.db
    

    • 建表
    create table mytable(id integer primary key, value text); 
    
    • 插入
    insert into mytable(id, value) values(1, 'jinks');  
    
    • 查询
    //.mode column
    //.header on
    
    select * from mytable;
    
    • 修改表结构
    alter table mytable add column email text
    
    • 创建视图
    create view nameview as select * from mytable;
    
    • 创建索引
    create index test_idx on mytable(value);
    

    其他常用操作

    • 显示表结构:
    .schema [table] 
    
    • 显示所有表和视图:
    .tables
    
    • 显示指定表的索引列表:
    .indices [table ] 
    
    • 导出数据库到 SQL 文件:
    .output [filename ]  
    
    .dump 
    
    .output stdout 
    
    • 导入数据库:
    .read [filename ] 
    
    • 格式化输出数据到 CSV 格式:
    .output [filename.csv ]  
    .separator ,  
    select * from test;  
    .output stdout 
    
    • 从 CSV 文件导入数据到表中:
    create table newtable ( id integer primary key, value text );  
    .import [filename.csv ] newtable 
    
    • 备份数据库:
    /* usage: sqlite3 [database] .dump > [filename] */
    sqlite3 mytable.db .dump > backup.sql 
    
    • 恢复数据库:
    /* usage: sqlite3 [database ] < [filename ] */  
    sqlite3 mytable.db < backup.sql 
    
  • 相关阅读:
    mysql性能分析工具
    vim使用大全
    Vue computed属性
    模板题 + KMP + 求最小循环节 --- HDU 3746 Cyclic Nacklace
    Greedy --- HNU 13320 Please, go first
    DFS --- HNU 13307 Galaxy collision
    HNU 13308 Help cupid
    Linux
    dp
    2015 Multi-University Training Contest 2 1006 Friends
  • 原文地址:https://www.cnblogs.com/jinkspeng/p/5275672.html
Copyright © 2011-2022 走看看