zoukankan      html  css  js  c++  java
  • SQL语句

     1 // 1 创建表
     2 
     3 语法:
     4 create table 表名(字段1 约束1 约束2, 字段2 约束1 约束2);
     5 
     6 // 上边的SQL语句的含义是:第一次 创建表,第二粗如果在执行这个SQL语句就会报错
     7 // 第二个SQL语句:如果这个表没有存在的情况下才会执行这个SQL语句
     8 create table if not exists 表名(字段1 约束1 约束2, 字段2 约束1 约束2);
     9 
    10 
    11 // 事例
    12 需求:
    13 创建一个student表,表中的字段有学号,姓名,年龄,学号约束条件:作为主键,自增,不能为空;姓名默认为'无名氏';年龄大于16岁
    14 create table student(s_id integer primary key autoincrement  not null, s_name text default '无名氏', s_age integer check (s_age > 16));
    15 
    16 // 2 插入数据
    17 语法:
    18 insert into 表名(字段1, 字段2, 字段3)values(值1, 值2, 值3);
    19 
    20 // 事例学生姓名,年龄
    21 insert into student(s_name, s_age)values('傻芳', 18);
    22 insert into student(s_name, s_age)values('自己', 17);
    23 
    24 // 3 更新数据
    25 语法:
    26 update 表名 set 字段名1 = 修改值1, 字段2 = 修改值2 where 条件;
    27 
    28 update student set s_age = 25 where s_age = 18;
    29 
    30 // 4 删除数据
    31 语法:
    32 delete from 表名 where 条件;
    33 // 需求:删除年龄为10岁的学生
    34 delete from student where s_age = 10;
    35 
    36 // 5 查询数据
    37 语法:
    38 select 要查找的字段 from 表名 where 条件;
    39 
    40 // 需求: 查询姓名为傻芳的所有信息
    41 select *from student where s_name = '傻芳';
  • 相关阅读:
    oracle多表关联删除的两种方法
    T100——汇总错误消息显示
    T100——程序从标准签出客制后注意r.c和r.l
    本地DataGrip连接阿里云MySQL
    mysql for mac 上的安装及用DataGrip连接
    mac 上安装vue模版-D2 Admin
    Python 3.7版本关于json.dump失效
    设置第三方的SMTP服务
    Apache 配置代理服务
    PyCharm 通过Github和Git上管理代码
  • 原文地址:https://www.cnblogs.com/crazygeek/p/5457872.html
Copyright © 2011-2022 走看看