MySQL基礎(chǔ)語(yǔ)法
把一些課上做的筆記搬來(lái)B站~
-- 創(chuàng)建庫(kù)
-- create database 數(shù)據(jù)名 charset=utf8;
-- use 數(shù)據(jù)庫(kù)名
-- 創(chuàng)建表
-- create table 表名(
-- 列名1 ?數(shù)據(jù)類型 約束類型,
-- 列名2 ?數(shù)據(jù)類型 約束類型,
-- .....,
-- 列名n ?數(shù)據(jù)類型 約束類型
-- )
-- 數(shù)據(jù)類型 int varchar double(18,2) decimal(18,2) datetime
-- 約束類型
-- 主鍵 primary key
-- 唯一 unique
-- 非空 not null
-- 默認(rèn) default
-- foreign key (列名) references 表名2(主鍵)
-- 添加數(shù)據(jù)
-- insert into 表名 values(數(shù)值1,數(shù)值2,....,數(shù)值n)
-- 查詢數(shù)據(jù)
-- select * from 表名 where 條件查詢
-- 查詢學(xué)生姓名、電話
-- select 列名1,列名2,....,列名n ?from 表名 where 條件查詢
-- 修改數(shù)據(jù)
-- update 表名 set 列名1=數(shù)值1,列名2=數(shù)值2,....,列名n=數(shù)值n where 條件查詢
-- 刪除數(shù)據(jù)
-- delete from 表名 where 條件查詢
-- 刪除數(shù)據(jù)庫(kù)
-- drop database 數(shù)據(jù)庫(kù)名
-- 條件查詢
-- 關(guān)系條件 ?> < >= <= != <> =
-- 邏輯條件 ? and or not
-- 不連續(xù)條件 ?where 列名 in(數(shù)值1,數(shù)值2);
-- 連續(xù)條件 where 列名 between 開(kāi)始的值 and 結(jié)束的值
-- 空值條件 where 列名 is (not) null
-- 模糊條件 where 列名 like '%%' ?_
-- 聚合函數(shù)
-- count()統(tǒng)計(jì)行數(shù)
-- sum(列名) 求和
-- avg(列名) 平均值
-- max(列名) 最大值
-- min(列名) 最小值
-- 排序
-- order by 列名1 asc 升序|desc 降序,列名2 asc 升序|desc 降序