SQLite快速入门二--表、视图的创建、修改、删除操作
Posted on 2012-02-20 14:58 work hard work smart 阅读(3432) 评论(0) 编辑 收藏 举报表、视图、索引的创建、修改、删除操作等
一、表的创建
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;
作者:Work Hard Work Smart
出处:http://www.cnblogs.com/linlf03/
欢迎任何形式的转载,未经作者同意,请保留此段声明!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步