mysql opaq数据库_MySql数据库
表:
字段 數(shù)據(jù)類型 約束
約束:主鍵,外鍵,非空,默認(rèn)值;
win + r 輸入cmd
輸入命令:mysql -u root -p。輸入密碼。
輸入命令注意:
1.命令結(jié)束符號是分號。
2.所有符號都是英文半角。
3.只有遇到分號,mysql才認(rèn)為結(jié)束。
4.多個命令用分號一行可用隔開。
5.引號要打全。
查看數(shù)據(jù)庫命令:
show databases;
創(chuàng)建數(shù)據(jù)庫:
create database 庫名;
刪除數(shù)據(jù)庫:
drop database 庫名;
進入數(shù)據(jù)庫:
use 庫名;
查看所有的表:
show tables;
創(chuàng)建表: 字段名 數(shù)據(jù)類型 約束
約束:主鍵:primary key
非空:not null
默認(rèn)值:default
創(chuàng)建表注意:
1.字段必須有字段名和數(shù)據(jù)類型。
2.多個字段用逗號分隔。
3.最后一個字段不要加逗號。
create table aa(
sno varchar(20) primary key,
sname varchar(20) default "老王",
ssex int(10)
);
查看表結(jié)構(gòu):
desc 表名;
刪除表:
drop table 表名;
數(shù)據(jù)的增刪改查:
添加:
添加 到 那個表(那些列) 值是 (值1,值2...);
insert into 表名 values(值1,值2...),(值1,值2...);
添加全字段可以省略表名后面的列
insert into aa(sno,sname,ssex) values(值1,值2,值3)
刪除:
刪除 從 那個表(刪除的內(nèi)容)
delete from 表名;
修改:
修改 那個表 設(shè)置 哪個字段=值
Update 表名 set 字段1 = 值1,字段2 = 值2.....
(as 改表頭)
查詢:
查詢 所有的字段 從 那個表;
select * from 表名;
查詢 學(xué)號字段 從 aa表;
select sno from aa;
(1)簡單查詢:
select * from 表名;
(2)條件查詢:
where后面加條件,條件要寫清楚。
select * from 表名 where 字段='值';
查詢多個條件:
select * from 表名 where 字段='值' and 字段='值';
或者用or 并且用and。
(3)模糊查詢:
select * from 表名 where 字段 like '% %'; ( _ 代表一個字 , %為任意多個字符)
(4)排序查詢:
select * from 表名 order by 字段 排序;(desc降序/asc升序)
(5)范圍查詢: (關(guān)系運算符,between...and...)
X
(6)離散查詢: (in,not in)
select * from 表名
(7)聚合查詢,統(tǒng)計查詢
(8)分頁查詢: (limit 從第幾條開始,取多少條數(shù)據(jù))
select distinct 字段 from 表名 limit (pagesize-1)*5,5
(9)去重查詢:
select distinct 字段 from 表名
(10)分組查詢
select count(*),Brand from Car group by Brand
select Brand from Car group by Brand having count(*)>3
高級查詢
1.連接查詢,對列的擴展
select * from Info,Nation
select Info.Code,Info.Name,Info.Sex,Nation.Name,Info.Birthday from Info,Nation where Info.Nation = Nation.Code
select * from Info join Nation
select * from Info join Nation on Info.Nation = Nation.Code
2.聯(lián)合查詢,對行的擴展
select Code,Name from Info
union
select Code,Name from Nation
3.子查詢
(1)無關(guān)子查詢
外層查詢 (里層查詢)
子查詢的結(jié)果當(dāng)做父查詢的條件
子查詢:select 字段 from 表名 where 字段='XX'
父查詢:select * from Info where 字段 = ''
select * from Info where 表名 = (select 字段 from 表名 where 字段='XX')
(2)相關(guān)子查詢
父查詢:select * from 表名 where 字段
總結(jié)
以上是生活随笔為你收集整理的mysql opaq数据库_MySql数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java图像增强_java图片对比度调整
- 下一篇: mysql-proxy安装包_Mysql