mysql学习(九)sql语句

SQL种类:

DDL:数据定义语言

DML:数据操作语言

DQL:数据查询语言

DCL:数据控制语言

DDL:

  1. show databases; //查询数据库
  2. create database if not exists sqldb;//创建一个数据库
  3. use sqldb; //使用一个sqldb
  4. show tables; //显示表
  5. create table if not exists cats(id int not null auto_increment, pid int not null default '0', name varchar(16) not null default '', desn text not null default '',  primay key(id), key name(name, pid)); //创建数据表
  6. create table if not null exists products(id int not null auto_increment, cid int not null default '0', name varchar(16) not null default '', num int not null default '0', price double(10, 2) not null default '0.00', desn text not null default '', primary key(id), key name(name, price));//创建表

DML:数据操作语言 insert update delete

  1. desc products; //查看表结构
  2. insert into products(cid, name, price, num, desn) values('0', 'dda', '10.20', '2', 'this is a java');// 插入记录
  3. insert into products values(null, '0', 'java', '10', '10.10', 'this is a java!');
  4. update procudts set num = 1 where id = 1;//更新语句
  5. update products set name = 'php', desn = 'this is php' where id = 2; //更新语句
  6. delete from products where id = 1;//删除id = 1的记录

DQL:数据查询语句

select [all | distinct]

[字段名 as 别名]

from

表名

[where  条件语句]

[group by ....]

[having....]

[order by...]

[limit count]

  1. where 语句 select update delete

逻辑运算(多个条件)

&&   ||  !

and  or  not

比较运算

<=>

>

<

=

!= / <>

>=

<=

IS NULL

NOT NULL

BETWEEN AND

NOT BETWEEN AND

IN

LIKE 模糊查询  _:一个任意字符 %:0个或者多个字符

NOT LIKE:

REGEXP 正则表达式

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/zhoulikai/p/3360302.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值