zoukankan      html  css  js  c++  java
  • SQLite快速入门二表、视图的创建、修改、删除操作

    表、视图、索引的创建、修改、删除操作等

    一、表的创建

    1、创建表

    create if not exists  table student(StuID integer);

    2、 创建带有缺省值的数据表:

    create table if not exists  schoolTable(schID integer default 0, schName varchar default 'hz');

    3、if not exists 使用

     如果已经存在表名、视图名和索引名,那么本次创建操作将失败。加上"IF NOT EXISTS"从句,那么本次创建操作将不会有任何影响.

    create table if not exists studentTest(StuID integer);

    4、primary key

    create table if not exists  studenttable (stuid integer primary key asc); 创建主键

    create table if not exists studenttable2 (stuid integer,stuName varchar, primary key(stuid,stuName)); 创建联合主键

    4 unique约束

    create table if not exists sutTest(stuID integer unique); 创建唯一性约束

    5 check约束

    create table if not exists sutTest2(stuID integer, ID integer, check(stuID > 0 and ID <0));

    二、表的修改

    1、修改表名

    alter table sutTest rename to stutest;

    2、向表中添加新列

    alter table  stuTest add column stuName varchar;

    三、表的删除

    drop table if exists stuTest 如果某个表被删除了,那么与之相关的索引和触发器也会被随之删除。 

    四、创建视图

    1、创建简单视图

    create view if not exists View_Corporate as select * from corporate where corid > 1

    2、创建临时视图

    create temp view tempView_Corporate as select * from corporate where corid > 1

    五、删除视图

    drop view if exists View_Corporate;

    六、索引的创建

    1、该索引基于corporate表的corID字段。

    create index cor_index on corporate(corID);

    2、该索引基于corporate表的corID,corname字段,,并且指定每个字段的排序规则

    create index cor_index2 on corporate(corID asc, corName desc);

    3、创建唯一索引

    create unique index cor_index3 on corporate(corID asc, corName desc);

    七、删除索引

    drop index if exists cor_index3;

    八、重建索引 reindex;

     重建索引用于删除已经存在的索引,同时基于其原有的规则重建该索引。

    九、数据分析 analyze;

    十、数据清理 vacuum;

  • 相关阅读:
    shell脚本模拟交互操作实现上传文件至sftp
    从文件A中去除掉文件B的内容
    Linux批量kill某个程序的进程
    单数据盘或者很多数据盘mount挂载到某个目录
    用户HTTP请求过程简单剖析
    linux服务器系统盘坏且系统盘为软raid的修复方法
    linux系统运行状态检查
    TCP的三次握手和四次挥手
    ES6嵌套对象的解构
    DRF框架在嵌套关系下实现嵌套对象字段的过滤
  • 原文地址:https://www.cnblogs.com/linlf03/p/2359009.html
Copyright © 2011-2022 走看看