一:資料型別:
整數型別(5種):
tinyint: byte
smallint: short
mediumint:
int:
bigint: long
浮點型和定點型:
float:
double:
decimal(m,i):
日期與時間型別:
year:yyyy 表示年份
date:yyyy-mm-dd 表示日期
time:hh-mm-ss 表示時間
datetime:yyyy-mm-dd hh-mm-ss 表示日期和時間
timestamp:yyyy-mm-dd hh-mm-ss 表示日期和時間,取值范圍小
字串和二進制型別:
char
varchar
binary
varbinary
blob 表示二進制大資料,pdf檔案,圖片等
tinytext,text,mediumtext,longtext 表示大文本資料
enum
set 表示字串的物件
bit 位
二:資料表的操作:
查看資料表:
desc [表名]
show table [表名]
修改資料表:
修改表名:alter table [舊表名] rename to [新表名];
修改欄位名:alter table [表名] change [舊欄位名] [新欄位名] [新欄位名]
修改欄位的資料型別:alter table [表名] modify [欄位名] [資料型別]
添加欄位:alter table [表名] add [新欄位名] 資料型別(約束)
洗掉欄位:alter table [表名] drop [欄位名]
修改欄位的排列位置:alter table [表名] modify [欄位名1] [資料型別] first/after [欄位名2]
洗掉資料表:drop table [表名]
添加資料: insert into 表名 values( ),( ),( );
更新資料: updata 表名 set id=01,name=' ' where id=1;
洗掉資料: delete from 表名 where id<5;
表的約束:
主鍵約束:
primary key:單欄位約束,多欄位約束
非空約束:
...not null
唯一約束:
...unique
默認約束:
...default 0
索引: 是為了高效率查找特定的資料,提高查詢速度
洗掉索引:
alter table drop index 索引名
drop index 索引名 on
創建索引:
創建表時創建索引:
普通索引: index([欄位名])
唯一索引: unique index [unique_id(id asc)] //asc,升序 desc,降序
全域索引: fulltext index [fulltext_id(id)]
單列索引: index [single_name(name(20))]
多列索引: index multi(id,name(20))
空間索引: spatial index nm(name)
在已建立表上創建索引:
create index
create [unique/spatial/fulltext] index [索引名] on 表名(id(10),name(20))
alter table
alter table 表名 add [unique/spatial/fulltext] index 索引名(id(20) asc)
單表查詢:
簡單查詢:
select陳述句:
按條件查詢:
where
in
between and
null
distinct
like: '%' 通配符查詢;'_' 通配符查詢
and(多條件查詢)
or
高級查詢:select
聚合函式:
count(),sum(),avg(),max(),min()
查詢結果排序:
select * from s1 order by id adc,item desc
分組查詢:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/97517.html
標籤:MySQL
