MySQL sql語句筆記

2021-09-11 08:26:07 字數 960 閱讀 7079

sql

插入

insert  [into]  表名  [(列名)] values  (值列表) -- [關鍵字] 可省略

insert into stu (name,age,city) values ('***',18,1)

更新

update 表名 set 列名 = 更新值 [where 更新條件]

update stu set name='sdfsdf',age=12 where id=1

刪除

delete [from]  表名 [where 《刪除條件》]

delete from stu where id=1

查詢

select    《列名》 

from 《表名》

[where 《查詢條件表示式》]

[order by 《排序的列名》[asc或desc]] -- asc正序排列,desc倒敘排列

select * from stu where id>2 order by id desc
select * from stu where id>2 limit 2
select distinct name,age from stu
函式查詢 將查詢的結果合併一列展示

select concat(name,age) from stu;

-- 大寫

select upper(name) from stu;

小寫select lower(name) from stu;

替換select replace(name,'海','大海') from stu

MySql Sql語句總結

建表語句 create table class id int primary key,class char 255 name varchar 4000 hobby text int 和 integer 是一樣的,只是為了簡寫罷了,主鍵宣告直接跟在定義後面,char和varchar char是固定長度...

MySQL SQL語句優化

檢視表定義 show create table users 檢視表的索引 show index from users 你要獲取第乙個表的所有資訊,你說全表掃瞄快呢還是索引掃瞄快呢?所以當你查詢庫 包括left join中的臨時庫 的所有資訊時,資料庫會選擇最優方法 全表掃瞄!s表dept id na...

Mysql sql語句回顧1

檢索出不存在相同值的列表可以加上distinct關鍵字 select distinct vend id from products 可以使用limit子句來限制返回結果的數量 select prod name from products limit 5 limit子句同樣擁有offset的功能,就是...