SQL常用语句总结

要点:
1.语法: 4.索引:
2.表:创建表,针对表的增删改查。 5.存储过程:
3.数据:增删改查。 6.触发器及锁...

一、SQL语言


1.主要操作语句:
1.对数据库操作:show ; use ; alert;

2.对表的操作:show ; desc ; drop ; alter;

3.对数据的操作:insert; delete ;update ;select;


2.表:
1.表的创建:

create table [name] (
[字段名] [类型] (not null) (auto_increment只有主键才有),
[字段名] [类型] (not null)
primary key(要作为主键的字段));

2.表的操作:

drop table [表名];//删除表

alter table [表名]
drop column [字段名];//删除某列

alter table [表名]
add [字段名] [类型];//添加某列

alter table [表名]
modify [字段名] [类型] default'默认值';//给某字段设置默认值



3.数据:
1.数据的定义:
字符串类型char varchar longvarchar
布尔值 boolean
字节 bit
整形 tinyint smallint integer bigint
浮点型 real float double
日期 date
时间 time

2.数据的操作:
对一条记录的:
插入 insert into [表名](要插入的字段名) value(,,,);
删除 delete from [表名] where 条件;
修改/更新 update [表名] set [字段1]= ,[字段2]= ,[字段3]= where 条件;
清空 truncate table [表名];
查询 见第三点

3.多种查询
Select简单查询:select*from [表名];
结果排序:select*from [表名] order by [某字段] desc;

条件查询:select语句后的where语句指定查询条件
条件:
多重条件:And or
比较条件:=,>,<,!=,!<,not+比较条件
所在范围:in(),not in()
是否为空:Is null,is not null
模糊匹配:like'%_\';%模糊匹配任意内容;_模糊匹配某字符;/转义;
例子:

Select*from userinfo where id>1 and id<5;
Select*from userinfo where name='a' or id='1';
Select*from userinfo where age in(19,20,21);
Select*from userinfo where name like '_abc\%';
Select userinfo.id,userinfo.name as 姓名 from userinfo;

分组查询:
Select[字段1],count([字段2])as num,..from[表名]group by [字段1/其他字段];
联合查询:
嵌套查询:

二、索引
详见 数据库学习之<索引>

(待补充----->
三、存储过程
理解:
实现:
四、触发器
理解:
实现:
五、锁
理解:
实现:
)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值