SQL基础知识整理

 

RDBMS 指关系型数据库管理系统,全称 Relational Database Management System。

Select

SELECT * FROM table_name;

  • Select * from Websites; 查看表中所有记录
  • Select distinct country from websites; 查看表中不重复的国家
  • Select * from websites where country='CN';
  • Select * from websites where id=1;
  • 文本值需要使用单引号括起来(大多数据库也支持双引号),数值不需要使用引号
  • <>不等于(或者!=)
  • Between 在某个范围内
  • Like 搜索某种模式
  • In 指定针对某个列的多个可能值
  • Select * from websites where sal > 2000 and sal < 3000;
  • Select * from websites where sal between 2000 and 3000;
  • Select * from websites where sal in (5000,2000,3000);
  • Select * from websites where comm is null;
  • 模糊查询:
    •  % 表示多个字值,_ 下划线表示一个字符;
    •  M% : 为能配符,正则表达式,表示的意思为模糊查询信息为 M 开头的。
    •  %M% : 表示查询包含M的所有内容。
    •  %M_ : 表示查询以M在倒数第二位的所有内容。
  • And 和 or

Select * from websites where country='CN' and alexa > 50;两个条件都成立时

Select * from websites where country='CN' or alexa >50;有一个条件成立时

Select * from websites where alexa > 15 and (country='CN' or country='USA');结合使用

Order by

Select * from websites order by country,alexa;

Order by a desc,b;

 

Insert

INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);

  • Insert into websites (name, url, alexa, country) values ('百度','https://www.baidu.com/','4','CN');一般自动生成的id字段是不用指定的
  • insert into select 和select into from 的区别
  • insert into scorebak select * from socre where neza='neza'   --插入一行,要求表scorebak 必须存在
    select *  into scorebak from score  where neza='neza'  --也是插入一行,要求表scorebak 不存在

Update

UPDATE table_name SET column1=value1,column2=value2,…  WHERE some_column=some_value;

UPDATE Websites SET alexa='5000', country='USA' WHERE name='菜鸟教程';

没有where的字句会更新所有记录

Delete

DELETE FROM table_name WHERE some_column=some_value;

 

3 SQL高阶教程

 

  •  
  • 2 SQL语法
  •  
  • 1 简介
  • SQL,指结构化查询语言,全称是 Structured Query Language。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值