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;



本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2012/02/20/2359009.html,如需转载请自行联系原作者

目录
相关文章
|
30天前
|
API 数据库 C语言
【C/C++ 数据库 sqlite3】SQLite C语言API返回值深入解析
【C/C++ 数据库 sqlite3】SQLite C语言API返回值深入解析
169 0
|
3月前
|
存储 数据库连接 数据库
Android数据存储:解释SQLite数据库在Android中的使用。
Android数据存储:解释SQLite数据库在Android中的使用。
42 0
|
2月前
|
存储 监控 安全
内网屏幕监控软件的数据存储与管理:使用SQLite数据库保存监控记录和配置信息
在当今数字化时代,安全和监控在企业和组织中变得至关重要。内网屏幕监控软件作为一种关键工具,帮助组织监视员工的活动并确保信息安全。这种软件不仅需要高效地记录和管理监控数据,还需要能够方便地进行配置和调整。本文将讨论如何使用SQLite数据库来保存监控记录和配置信息,并介绍如何通过自动化机制将监控到的数据提交到指定网站。
163 2
|
12天前
|
SQL 关系型数据库 数据库
Python中SQLite数据库操作详解:利用sqlite3模块
【4月更文挑战第13天】在Python编程中,SQLite数据库是一个轻量级的关系型数据库管理系统,它包含在一个单一的文件内,不需要一个单独的服务器进程或操作系统级别的配置。由于其简单易用和高效性,SQLite经常作为应用程序的本地数据库解决方案。Python的内置sqlite3模块提供了与SQLite数据库交互的接口,使得在Python中操作SQLite数据库变得非常容易。
|
17天前
|
关系型数据库 MySQL 数据库连接
Python+SQLite数据库实现服务端高并发写入
Python中使用SQLite内存模式实现高并发写入:创建内存数据库连接,建立表格,通过多线程并发写入数据。虽然能避免数据竞争,但由于SQLite内存模式采用锁机制,可能在高并发时引发性能瓶颈。若需更高性能,可选择MySQL或PostgreSQL。
23 0
|
1月前
|
关系型数据库 数据库 C++
嵌入式数据库sqlite3【基础篇】基本命令操作,小白一看就懂(C/C++)
嵌入式数据库sqlite3【基础篇】基本命令操作,小白一看就懂(C/C++)
|
1月前
|
存储 SQL 数据库
django如何连接sqlite数据库?
django如何连接sqlite数据库?
46 0
|
2月前
|
SQL 数据库管理
sqlite语句order by两个字段同时排序处理
sqlite语句order by两个字段同时排序处理
21 0
|
2月前
|
SQL 关系型数据库 MySQL
Python中的数据库操作:SQLite与MySQL的连接
Python中的数据库操作:SQLite与MySQL的连接
123 0
|
2月前
|
SQL 存储 数据库
艺术型轻量级数据库 --Sqlite
艺术型轻量级数据库 --Sqlite

热门文章

最新文章