美文网首页
iOS 基本SQLite语句

iOS 基本SQLite语句

作者: Sparkle_S | 来源:发表于2016-12-01 14:06 被阅读0次

    建表命令(create table):

    create table if not exists student(s_id integer primary key autoincrement not null,
    s_name text default'无名氏',s_age integer check(s_age>200))
    //格式:create table if not exists 表名 (字段1 约束1 约束2···,字段2 约束1 约束2···);
    1、create table:建表关键字
    2、if not exists:如果创建的表存在就不再创建
    3、表名
    4、字段名
    5、对字段的约束(可以有多个)
    

    数据库插入命令(insert)

    insert into student(s_name, s_age) values('贝爷',30);
    //格式:insert into 表名(字段1,字段2,···)values (字段1值,字段2值,···);
    1、insert into:插入语句关键字
    2、要插入的的表
    3、要向哪些字段插入数据
    4、values:值关键字
    5、要插入的数据(要和字段顺序相同)
    

    数据库更新命令(update)

    update student set s_age = 100 where s_age = 10;
    //格式: update 表名 set 字段1 = 修改值1,字段2 = 修改值2,··· where 条件
    1、update , set:更新数据关键字
    2、要更新的表
    3、需要更新的字段和更新后的值
    4、where:条件关键字
    5、要修改的数据需要满足的条件(条件可以有一个或多个,使用and或or进行连接)
    

    数据库删除命令(delete)

    delete from stu where s_age = 10;
    //格式: delete from 表名 where 条件
    1、delete from 删除关键字
    2、要删除数据的表名
    3、where:条件关键字
    4、删除的数据满足的条件
    

    数据库查询命令(select)

    select * from student where s_sex='男';
    select s_name ,s_age from student where s_sex = '男'
    //格式:select 要查找的字段 from 表名 where 条件;
    1、select :查询关键字
    2、要查找的字段(通配符*代表查找所有字段)
    3、from 表名:from是关键字,后面是要查找的表
    4、where:条件关键字
    5、要查找的数据满足的条件
    

    期待你的评论建议O(∩_∩)O~

    相关文章

      网友评论

          本文标题:iOS 基本SQLite语句

          本文链接:https://www.haomeiwen.com/subject/jzexmttx.html