一、SQL语句组成
1.DDL(数据定义);
2.DML(数据操作);
3.DQL(数据查询);
4.DCL(数据控制);
二、数据类型
1.整数
1)tinyint
2)smalliint
3)mediumint
4)int
5)bigint
2.浮点型
1)float
2)double
3)decimal
3.字符串
1)char
2)varchar
3)tinytext
4)text
5)mediumtext
6)longtext
4.日期、时间
1)date
2)time
3)year
4)detetime
5)timestamp
5.二进制
1)tinyblob
2)blob
3)mediumblob
4)longblob
三、基础语法
1.创建数据库
create database +数据库名
2.显示数据库
show databases
3.丢弃数据库
drop database+名称
4.使用
use+名称
5.创建表
create table 表名(列名 数据类型 约束);
6.看表
desc+表名称
7.重命名
rename
8.描述
describe
9.改列名
alter table 表名 change 原列名 新列名 类型
10.删除列
alter table 表 drop 列
11.删除主键约束
alter table 表名 drop
12.删除索引名
alter table 表名 drop index 索引名
13.创建索引
create index 索引名 on 表名(列名);
14.默认约束
alter table 表明 change 原列 新列 数据类型 default 默认值
15.删除外键约束
alter table 表名 drop foreignlcey 外键名称
16.插入行数据
insert into 表名(列名)values (值);
17.主键自动增长
主键+auto_increment;
18.查询语句
select( )from 表;(括号中包含*、列、distinct三种类型,*代表所有数据)
19.数据排序
select 列 from 表 order by 列 a ASC\DESC(ASC代表升序,desc代表降序)
四、约束
1.唯一性
unique
2.非空约束
not null
3.默认
defaule