常用sql

♀尐吖头ヾ 提交于 2020-03-08 00:24:15

一.基础

create/drop  database dbname / table tbname(新建/删除数据库、表)

alter table tbname add 字段名 类型

create  index indexname on tbname(字段名) 创建索引

drop index indexname 删除索引

增删改查:

insert into tbname (字段a,字段b) values(a,b)

delete from tbname where id ='1'

update table set 字段= a where id=‘1’

 select * from tbname

count,sum,avg,max,min

select distinct * from tbname order by id desc 去重复、倒序

筛选条件 where and ,having,group by,in,not in,not exists, select top 10 * from tbname,随机select newid(),order by newid()

 

多表查询

select * from tba a left join tbb b on a.id=b.id

right join on

select * from tba where a in (select * from tbb)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!