SQLite快速入门二--表、视图的创建、修改、删除操作
2013-05-18 14:39
696 查看
一、表的创建
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;
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;
相关文章推荐
- SQLite快速入门二--表、视图的创建、修改、删除操作
- 表、视图、索引的创建、修改、删除操作等
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表 (转)
- 表、视图、索引的创建、修改、删除操作等
- SQLite 入门教程(二)创建、修改、删除表
- oralce视图创建修改删除操作
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程(二)创建、修改、删除表
- SQLite 入门教程二 SQLite的创建、修改、删除表
- oracle 视图 创建 操作 简单 复杂 基表 不存在 增 删 改 插入 修改 删除 查看 结构
- SQLite 入门教程(二)创建、修改、删除表
- oracle 创建视图、修改视图、删除视图、利用视图操作基本表
- oracle 创建视图、修改视图、删除视图、利用视图操作基本表
- SQLite 入门教程(二)创建、修改、删除表
- python操作数据库之sqlite3打开数据库、删除、修改示例