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;

  • 相关阅读:
    寒假短期学习计划
    PAT 1001 A+B 解题报告
    JavaScript 原型链、继承
    JavaScript 数据扁平化处理
    每周一篇React: 高阶 hoc_component 使用
    每天一道算法题: day1 翻转图像
    项目中下载加权,你是怎么做的,欢迎评论。
    前端封装验证码方法,封装验证码类
    文件下载之后默认不打开实现方式
    文件下载之后默认不打开实现方式
  • 原文地址:https://www.cnblogs.com/linlf03/p/2359009.html
Copyright © 2011-2022 走看看