SQL语言及语句的使用

database学习:常用数据库:1.mysql 2.oracle 3.sqlserver 4.DB2
SQL语言:
sql语言分类:
1.DDL数据定义语言 create 对象 对象名,alter 对象 对象名, drop 对象 对象名
2.DML数据操纵语言 insert++commit增 update++commit改 delete++commit删
3.DQL数据查询语言 select查
4.DCL数据控制语言 DBA(数据管理员)使用
desc(describe)对象名:显示该对象结构
DDL语句:创建或者删除、索引等数据库对象的语句
创建表的语法:create table 表名(字段一 数据类型(字符长度)...,字段一 数据类型(字符长度)..., ....)
修改表的表名:rename 表名 to 新表名
删除表的语法:drop table 表名
追加表的列:alter table 表名 add(字段 数据类型(字符长度)...)
删除表的列:alter table 表名 drop(col1,col2,...)
修改表的列的类型:alter table 表名 modify(column newDatatype)
修改表的列的名字: alter table 表名 rename column col1 to col2
DML语句:
增加数据语句:insert into 表名(字段1,字段2,...) values(value1,value2,...)
修改数据语句:update 表名 set 字段1=value1,字段2=value2,... where 条件
删除数据语句:delete from 表名 where 条件
DQL语句:查询数据库表对象的语句。
语法:select col1,col2,col3,... from 表名 where 条件
语句: select * from 表名 where 条件:查询该表所有字段
distinct关键字:



like关键字:模糊查询。like语句不加百分号或下划线(下划线表示一个字符,百分号表示0个到多个字符),那么他就是等于符号。如下:
select * from user where password LIKE '%i%'/*查询password中有i的数据*/
select * from user where password LIKE '_____a%'/*查询password中在a之前有五个字符的数据*/
select * from user where password LIKE '___f'/*查询password中以F结尾且在f之前有三个字符的数据*/
select * from user where password LIKE '%' /*查询所有数据*/
select * from user where password LIKE '_____%'/*查询至少有五个字符的数据*/
select * from user where password not LIKE 'a%'/*查询password中以a开头的数据*/*/
select * from user where password LIKE '%s%' and password LIKE '%d%'/*查询password中有a和d的数据*/
select * from user where password LIKE '%a%' or password LIKE '%d%'/*查询password中没有a和d的数据*/
ESCAPE关键字:自定义字符如下:
select * from user where password LIKE '%\文%%' ESCAPE '文'/**/
in关键字:包含。如下:
select * from user where userId=2 or userId=3 or userId=5 /*查询userId为2,3,5的三条信息*/
select * from user where userId in(2,3,5)/*查询userId为2,3,5的三条信息*/
select * from user where userId not in(2,3,5)/*查询userId不为2,3,5的信息*/
排序:asc升序,desc降序.如下:
select * from user where userId in(2,3,5) ORDER BY userId asc /*按userId升序排序*/
select * from user where userId in(2,3,5) ORDER BY userId desc/*按userId降序排序*/

select * from user where userId in(2,3,4) ORDER BY userId desc,flag asc/*按userId降序,flag升序排序*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值