sql基本的增删查改语句

1、增---用于向表中插入新的行/数据   
语法:insert into 表名(值1,值2,值3。。。) values(值1,值2,值3,。。。)
或者 语法:insert [into] <表名> [列名] values <列值>
例:insert into Strdents (姓名,性别,出生日期) values ('王伟华','男','1983/6/15')
语法:insert into <已有的新表> <列名> select <原表列名> from <原表名>
例:insert into addressList ('姓名','地址','电子邮件')select name,address,email from Strdents

2、删除---使用delete删除语句
语法:delete from <表名> [where <删除条件>]  
<!-- 注意:删除整行不是删除单个字段,所以在delete后面不能出现字段名 -->
语法:delete *(指定列) from 表名 where 列名 = ‘张益达’<!-- 在使用delete删除语句时,必须使用where语句。 -->
语法:truncate table <表名>
例:truncate table addressList
注意:删除表的所有行,但表的结构、列、约束、索引等不会被删除;不能用于有外建约束引用的表

3、查询---select 
1).查询所有数据行和列,*代表所有列
例:select * from a <!-- 说明:查询a表中所有行和 -->
2).查询部分行列--条件查询
例:select i,j,k   from  a   where f=5 <!-- 说明:查询表a中f=5的所有行,并显示i,j,k3列 -->
3).在查询中使用as更改列名
例:select name as 姓名 from a where  gender='男'
<!-- 说明:查询a表中性别为男的所有行,显示name列,并将name列改名为(姓名)显示 -->
4).查询空行
例:select name from a where email is null
<!-- 说明:查询表a中email为空的所有行,并显示name列;SQL语句中用is null或者is not null来判断是否为空行 -->
5).在查询中使用常量
例:select name '北京' as 地址 from a <!-- 说明:查询表a,显示name列,并添加地址列,其列值都为'北京' -->
6).查询返回限制行数(关键字:top )
例1:select top 6 name from a
<!-- 说明:查询表a,显示列name的前6行,top为关键字(oracle 中没有top关键字用rownum替代) -->
select   *   from   a where   rownum<6  
7).查询排序(关键字:order by , asc , desc),order by 是对指定列进行 升序 asc/降序 desc 排序
例:select name from a where grade>=60 order by desc                     
升序语法:select StudentID from Student order by student asc
降序语法:select StudentID from Student order by student desc

4、修改---update语句:用于对表中的数据进行修改。   
语法:update 表名 set 列名 = 新值 where 列名 = 要修改的值
语法:update <表名> set <列名=更新值> [where <更新条件>]
例:update addressList set 年龄=18 where 姓名='王伟华'
注意:set后面可以紧随多个数据列的更新值(非数字要引号);where子句是可选的(非数字要引号),用来限制条件,如果不选则整个表的所有行都被更新
原文地址:https://www.cnblogs.com/xi-li/p/10103328.html