您的位置:首页 > 移动开发 > Android开发

Android SQLite数据库判断某张表是否存在的语句

2013-12-25 19:46 387 查看
1、可以在创建表之前判断,这样就不会重新创建,create table if not exists Student(name text primary key, code integer); 比平时多了if not exists


2、

Cursor cursor = db.rawQuery("select name from sqlite_master where type='table';", null);
while(cursor.moveToNext()){
//遍历出表名
String name = cursor.getString(0);
Log.i("System.out", name);
}




3、

String sql = "select count(*) as c from sqlite_master where type ='table' and name ='Student';";
cursor = db.rawQuery(sql, null);
if(cursor.moveToNext()){
int count = cursor.getInt(0);
if(count>0){
result = true;
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: