参考:
http://www.cnblogs.com/rockdean/articles/2425843.html
http://blog.csdn.net/nupt123456789/article/details/7891887
http://www.cnblogs.com/helloandroid/articles/2150272.html
http://blog.csdn.net/janronehoo/article/details/7078142
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
创建数据库:
"CREATE TABLE IF NOT EXISTS students (_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age INTEGER,grade INTEGER, info VARCHAR)
db.execSQL("...“)
删除数据库表
DROP TABLE IF EXISTS students
db.execSQL("...“)
插入数据:
INSERT INTO students VALUES (NULL,?,?,?,?)", new Object[]{"张三",21,98,"南京邮电大学 电子信息工程"}
db.execSQL("...“)
更新数据:
update students set age = ?,school = ? where name = ?,new Object[]{21,"南京邮电大学 电子信息工程","张三"}
db.execSQL("...“)
删除数据
delete from students where name = ? ,new Object[]{"张三"}
db.execSQL("...“)
选择数据
SELECT * FROM students WHERE grade >= ?", new String[]{"86"}
db.execSQL("...“)
扩展:
desc<table>//查看表结构
select*from<table>//查询所有更
select , fromtable ;//查看指定列
selectdistinct , fromtable ;//非重复查询
insert into users(_id,username,password) select*from users;//复制
select username from users where username like'S%' ;//非重名字首字母为大写S的用户
select username from users where username like'__S%' ;//非重名字第三个字母为大写S的用户
select*from users where _id in(001,220,230);
select*from user order by _id;//以id的顺序排列
select*from user order by _id desc;//以id反的顺序排
onUpgrade中对表字段增删:
1.alter
alter table student add column addr text default null
2.不支持对列的改名和修改类型等操作,想要操作官方给出的方法是先备份原表数据到临时表,然后删除原表,再创建新的表结构,然后导入临时表的数据
BEGIN TRANSACTION; CREATE TEMPORARY TABLE t1_backup(a,b); INSERT INTO t1_backup SELECT a,b FROM t1;#复制 DROP TABLE t1; CREATE TABLE t1(a,b); INSERT INTO t1 SELECT a,b FROM t1_backup; DROP TABLE t1_backup; COMMIT;