码迷,mamicode.com
首页 > 数据库 > 详细

SQL语句

时间:2016-05-04 11:52:32      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

 

 1 // 1 创建表
 2 
 3 语法:
 4 create table 表名(字段1 约束1 约束2, 字段2 约束1 约束2);
 5 
 6 // 事例
 7 需求:
 8 创建一个student表,表中的字段有学号,姓名,年龄,学号约束条件:作为主键,自增,不能为空;姓名默认为无名氏;年龄大于16岁
 9 create table student(s_id integer primary key autoincrement  not null, s_name text default 无名氏, s_age integer check (s_age > 16));
10 
11 // 2 插入数据
12 语法:
13 insert into 表名(字段1, 字段2, 字段3)values(值1, 值2, 值3);
14 
15 // 事例学生姓名,年龄
16 insert into student(s_name, s_age)values(傻芳, 18);
17 insert into student(s_name, s_age)values(自己, 17);
18 
19 // 3 更新数据
20 语法:
21 update 表名 set 字段名1 = 修改值1, 字段2 = 修改值2 where 条件;
22 
23 update student set s_age = 25 where s_age = 18;
24 
25 // 4 删除数据
26 语法:
27 delete from 表名 where 条件;
28 // 需求:删除年龄为10岁的学生
29 delete from student where s_age = 10;
30 
31 // 5 查询数据
32 语法:
33 select 要查找的字段 from 表名 where 条件;
34 
35 // 需求: 查询姓名为傻芳的所有信息
36 select *from student where s_name = 傻芳;

 

SQL语句

标签:

原文地址:http://www.cnblogs.com/crazygeek/p/5457872.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!