1. 程式人生 > 其它 >前端的學習之路:初級HTML---超連結

前端的學習之路:初級HTML---超連結

技術標籤:資料庫基礎mysql

進入phpStudy2016自帶的資料庫(命令列)
在命令列中,上鍵可以複製上一行命令

#-u賬戶 root
#-p密碼 root
mysql -u root -p 
root
show databases; #檢視有什麼庫
use test1; #進入test1資料庫
select database(); #檢視當前所在的資料庫
show tables; #檢視資料庫有什麼表
desc apple; #檢視apple表

create database test2; #新建一個test2資料庫
use test2;
create table pea(id int
(8),name varchar(255)); #新建一個pea表 alter table pea add love varchar(255); #給pea表新增一個love欄位 alter table pea drop love; #刪除love欄位 alter table pea change name username varchar(25); #將欄位名name改為username,並且更改型別 drop database test2; #刪除test2資料庫
use test1;
insert into apple values(1,'apple1'); #插入資料(1,'qpple1')
#輸出表qpple select * from apple; insert into apple values(2,'apple2'),(3,'apple3'); insert into apple(name) value('apple4'); #單獨插入name欄位的資料 select id,name from apple; select * from apple where id='apple1';

MySQL具有相容性

insert into apple values(3,'APPLE3');
select * from apple where name='apple3'
;

在這裡插入圖片描述

update apple set name='test' where name='APPLE3'; #修改資料
update apple set id=4,name='apple4' where name='test'; #修改多個欄位的資料

update apple set name='test'; #如果沒有限定條件,則會將所有的資料更改為'test'
delete from apple where id=4; #刪除單個數據
delete from apple; #刪除所有資料
select *
from apple
order by 1; #以第一個欄位進行排序,預設為升序[asc]

select *
from apple
order by name; #以name欄位進行排序

select *
from apple
order by id desc; #以欄位id進行倒序排序
select *
from apple
limit 0,1; #從第1行開始,取1行

select *
from apple
limit 2,2; #從第3行開始,取2行
select group_concat(id) from apple; #多行資料一起輸出

在這裡插入圖片描述

select group_concat(id,name) from apple;

在這裡插入圖片描述

select *
from apple
where name like %a%; #查詢包含a的所有值

select *
from apple
where name like a%; #查詢a開頭的所有值

select *
from apple
where name like %a; #查詢a結尾的所有值
select sleep(2); #休眠函式,伺服器推遲2秒返回資料

運算子

+ - * /
and or not
select *
from apple
where id=3 and name='apple3';
select *
from apple
where id in (1,3);

在這裡插入圖片描述

select *
from apple
where id in (1,2,3);
select *
from apple
where id=1 and sleep(2); #當查詢到符合條件的資料時,沉睡2s,不輸出符合條件的資料

select *
from apple
where id=1 or sleep(2); #查詢所有的資料都沉睡,並輸出符合條件的資料
#將兩張表上下連線
#union不輸出重複值
#union all輸出重複值
select * from apple
union 
select * from pea;

select * from apple where id=1
union
select * from pea;

select * from apple
union all 
select * from pea;
select 'orange' from apple; #不斷輸出orange
#union欄位數必須相同,如果欄位數不同,可以新增
select id,name,'NULL' from apple
union all
select * from banana; #假設banana有三個欄位
#子查詢
select *
from apple
where id in
	(select id
	from watermelons
	where name='watermelons3');