第三章 管理数据库表
表的创建:
约束条件:null可以放空值 not null不能放空值
default 默认值
UNIQUE 唯一约束 可以放null 并且允许放多个null //unique 独一无二的adj
primary key 主键约束 主键不能为null 不能重复 //primary 主要的adj
create table City(
ID integer primary key autoincrement,
Name char(35) not null default '',
CountryCode char(3) not null default '',
District char(20) not null default '',
Population int(11) not null default ''
);
修改表:ALTER TABLE
修改表名:ALTER TABLE 表名1 RENAME TO 表名2
alter table tablename1 rename to tablename2;
添加新列:ALTER TABLE 表名 ADD COLUMN 新的字段
alter table City add clumn LocalName varchar(35) not null default '';
删除表:DROP TABLE
DROP TABLE IF EXISTS 表名 //exist 存在v
drop table if exists table1;
SQLite数据类型----“无类型的”
但是为了易读,和可移植性 我们创建表的时候要声明数据类型
SQLite支持类型近似 根据内部的近似机制 将传入的数据进行近似转换
Integer类型 REAL类型(8字节浮点数) TEXT类型 BLOB类型(二进制) 日期时间类型(TIME/DATA/TIMESTAMP)//stamp 戳 印记 n
操作表中数据:
insert into 表名(xxx, xxx,xxx) values(xxx,xxx,xxx),...(xxx,xxx,xxx);
insert into 表1(xx,xx,xx) select(xx,xx,xx) from 表2;
从表2取以上字段插入表1 要注意类型和约束匹配
update 表名 set 字段名=xxxx;
delete from 表名 where 条件;
posted on 2015-12-05 16:21 starFarming 阅读(120) 评论(0) 编辑 收藏 举报