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 = '傻芳';
原文地址:https://www.cnblogs.com/crazygeek/p/5457872.html