SQL的核心基礎(chǔ)語法 | 快速入門MySQL

SQL核心基礎(chǔ)語法
create database 數(shù)據(jù)庫名; #新建數(shù)據(jù)庫
use 數(shù)據(jù)庫名; #指明數(shù)據(jù)庫
create table 表格名 ( 列名1 int auto_increment primary key, 列名2 varchar() not null, 列名3 date null);??#int整形,varchar字符型,date日期
insert into 數(shù)據(jù)庫名.表格名(列名1,列名2,列名3) values (數(shù)值1,數(shù)值2,數(shù)值3);??#插入
select * from 表格名 /select 列名1 列名2 from 表格名 #查詢?
select distinct * from 表格名?#查詢?nèi)ブ?/p>
select * from 表格名 where(not) 條件 order by 列名 desc #分組排序 desc從高到低,從大到小/默認(rèn)為asc
alter table 數(shù)據(jù)庫名.表格名 add 列名 數(shù)據(jù)類型 默認(rèn)條件 #alter table egg.eggs_record add stock int null; ##增加表格列名
updata 數(shù)據(jù)庫名.表格名 set where 條件 #更新
delete from 數(shù)據(jù)庫名.表格名 #刪數(shù)據(jù)
drop table 數(shù)據(jù)庫名.表格名?#刪表
drop database 數(shù)據(jù)庫名?#刪庫
select * from inner 表1 join 表2 on 表1.列名1 = 表2.列名1; #取交集
select country from 表1 union select country from 表2 # union all 有重復(fù)值?
select * from 表1 left join 表2 on 表1.列名1 = 表2.列名1; #左連接
select * from 表1 rigtht join 表2 on 表1.列名1 = 表2.列名1 #右連接
?