美文网首页
简单的sql语句

简单的sql语句

作者: Leon_Jiang | 来源:发表于2018-04-12 08:51 被阅读0次

    1 创建sql表
    create table IF NOT EXISTS t_tudent_2 (id integer PRIMARY KEY AUTOINCREMENT, name text, age integer, score real ) ;

    2 删除表
    DROP TABLE IF EXISTS t_student ;

    3 增加数据
    INSERT INTO t_tudent_2 (id, name, age, score) VALUES (2, 'jack2', 21, 98) ;

    4 更新数据库
    UPDATE t_tudent_2 SET age = 20 , id = 1 ;

    5 条件语句 (where条件, and = && , or == ||, where a =(is) b, where a =(is not) b )
    1)UPDATE TABLE t_student SET score = 60 WHERE age < 20 ;
    2)年龄大于10 并且 姓名不叫jack的记录, 年龄都该成5
    UPDATE TABLE t_student SET age = 5 WHERE age > 10 AND name != 'jack' ;

    1. 删除年龄小于10 或者 年龄大于30的记录
      DELETE TABLE t_student WHERE age < 10 OR age > 30 ;

    6 查询语句
    1)SELECT name , age FROM t_student WHERE age > 10 and score >= 60 ;
    2)别名(空格或者AS)
    SELECT s.name , s.age, s.class_id FROM t_student AS s WHERE age > 10 and score >= 60 ;
    SELECT name sname , age sage, class_id sclass_id FROM t_student s WHERE age > 10 and score >= 60 ;
    3)查数量(count)
    SELECT count(s.name) FROM t_student s where score >= 60 ;
    4)排序(ORDER BY , asc 升序, desc降序)
    SELECT * FROM t_student WHERE score >= 60 ORDER BY score asc , age asc ;
    5)限制数量(limit(A , B)A-从A之后,B-几条数据)
    SELECT * FROM t_student WHERE score >= 60 LIMIT 0, 10 ;

    1. 简单约束
      not null 不为空
      unique 唯一
      deafult 默认值
      例 : CREATE TABLE t_student2 (id integer PRIMARY KEY AUTOINCREMENT, name text NOTNULL UNIQUE, age integer NOTNULL DEFAULT 1) ;
      7 查询语句表连接查询 ()
      -- 查询班级是0316ios的所有学生
      SELECT * FROM t_student s , t_class c WHERE s.class_id = c.id AND c.name == '0316ios';

    相关文章

      网友评论

          本文标题:简单的sql语句

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