sql指令,增,删,查,改

 

insert into table (name,sex,age) values('张三',‘男’,‘20’)   向表中的name,sex,age,分别添加张三,男,20的内容

select   “要查找的东西” from  "从哪一个表查"        *代表所有

select    name where table where name='肖淇'   在表中查询名字为肖淇的内容

delete   from table   where name='肖淇'  在表中删除名字为肖淇的内容

delete  from table 删除整个表中的内容

Drop  table 表明  删表, 整个数据表连锅端掉;
Delete  from where id=2,删数据,只删除表中部分数据;
Truncate  table 表名, 初始化数据表, 表结构不变,数据清空,且主键 1 开始

update   table set name='张三' where name='肖淇'    将表中名字为肖淇的内容改为张三

 

 

拓展:

排序

select * from table order by age   查询表中所有信息,并按年级升序排序

select * from table order by age  desc  查询表中所有信息,并按年级降序排序

 

返回唯一不同的值

 select  distinct age from table   查询表中不同的年龄有那些

 

and ,or

select * from table where sex='男' and age>20 查询表中性别为男并且年龄大于20的列

select * from table where sex='女' or age>20 查询表中性别为女或者年龄大于20的列

 

模糊查询

select * from dbo.chanping where name like '肖%'  查询以肖开头的所有内容

正则查询

SELECT * from jsh_account_head where id REGEXP'[1-3]'  查询以1-3开头的所有内容

SELECT * from jsh_account_head where id REGEXP'[^1-3]' 查询不以1-3开头的内容

SELECT * from jsh_account_head where id REGEXP'^[129]' 查询以1,2,9开头的内容

SELECT * from jsh_account_head where id like '10_' 查询以10开头的三位字符的内容_表示一个字符

SELECT * from jsh_account_head where id like '%0%'  查询内容id中间含有0的内容

SELECT * from jsh_depot_head where type in ('入库','出库')  查询type为入库和出库的所有内容

SELECT * from jsh_depot_head where type='入库'or type='出库'  与上一条相同的功能

 

表连接

left join     on

左右连接

select * from user_name left join user_age on user_name.id=user_age.id    姓名表和年龄表左连接,并查询id相同的相连,但是做连接只影响右表,反之右连接也与左连接同理,结果如下图:

 

 

 

交叉连接

 

交叉联接返回左表中的所有行,左表中的每一行与右表中的所有行组合

inner join      on

SELECT user_name.* ,user_xiangxi.* from user_name INNER JOIN user_xiangxi on user_name.id=user_xiangxi.id      查询姓名表,详细表的所有内容,显示姓名表所有内容,以id相同的条目进行拼接,如图:

 

 

内连接

SELECT * from user_age,user_name WHERE user_age.id=user_name.id     查询年龄表,姓名表中,两表id相同的所有内容

 

  外连接和内连接的区别

 

内连接:指连接结果仅包含符合连接条件的行,参与连接的两个表都应该符合连接条件。

 

外连接:连接结果不仅包含符合连接条件的行同时也包含自身不符合条件的行。包括左外连接、右外连接和全外连接。

 

posted @ 2021-06-12 15:25  小破的博客  阅读(272)  评论(0编辑  收藏  举报