標籤:
1.資料庫的簡介1.1 什麼是資料庫,就是一個檔案系統,使用標準sql對資料庫進行操作1.2常見的資料庫oracle 是oracle公司的資料庫,是一個收費的大型的資料庫
DB2,是IBM公司的資料庫,是一個收費的大型資料庫;
SQLSever,是微軟公司的資料庫,是中型的資料庫
MYsql資料庫 被oracle收購了,
SQLite資料庫,嵌入式小型資料庫,應用在用戶端開發中;
1.3 關聯式資料庫關聯式資料庫儲存的是實體之間的關係,
使用ER圖進行表示實體之間的關係
2. mysql資料庫的安裝與卸載
3. mysql資料庫的儲存結
2.1 有多個資料庫在每個資料庫中有多個資料庫表
在每個表中有多個記錄
2.2 學習的就是使用標準sql對資料庫、資料庫表、表中記錄的操作
4. sql的介紹4.1 Structured Query Language, 結構化查詢語言 (SQL)
4.2 非過程性語言,直接運行,不需要依賴於其他東西
4.3 sql對資料庫、資料庫表、表中記錄的操作
4.4 sql的分類 DDL 資料定義語言 (Data Definition Language)
建立資料庫,建立資料庫表的操作
常用的語句 create
DML 資料操作語言
對資料庫表記錄的操作
常用的語句 insert update delete
DCL 資料控制語言
DQL 資料查詢語言
對資料庫表裡面的記錄進行查詢操作
使用語句 select
5. 使用sql對資料庫進行操作5.1 啟動mysql //--- mysql -u root -p
5.2 輸入安裝資料庫密碼
5.3 建立資料庫 //--- create database mydatabase;
5.4 擷取當前所有的資料庫列表 //---show databases;
5.5 使用上述建立 的資料庫 mydatabase //--- use mydatabase
5.5 刪除資料庫 drop databaese mydatabase;
5.6 切換到使用的資料庫 use mydatabase;
6. 使用sql對資料庫表的操作
6.1建立資料庫表 create table mytable (
id int ,
name varchar(40),
sex varchar(40),
)
6.2 擷取當前所有的資料庫表列表 show tables;
6.3 擷取指定資料庫表的結構 desc mytable;
6.4 向指定資料庫表中添加 資料 insert into mytable values(1,‘lishi‘,‘man‘);
6.5 擷取指定資料庫表的內容資料
6.5.1 擷取其中的所有的資料內容 select * from mytable;
6.5.2 擷取其中指定欄位的資料內容 select name,sex from mytable;
6.5.3 擷取其中指定欄位的資料內容 select * from mydatabase where id =1;
6.6 mysql 的約束有三個
6.6.1 not null 非空約束
6.6.2 auto_increment 在主鍵,讓主鍵是自動成長
當使用了自動成長後,欄位的類型必須是int類
6.6.3 unique 唯王性約束
6.7 建立帶約束的表 create table mytable(
id int primary key,
name varchar(50) not null
)
create table stu (
id int primary key auto_increment,
sname varchar(40),
sex varchar(40)
)
6.8 刪除表 drop table mytable;
6.9 對錶中的資料進行修改的操作 update mytable name = ‘abd‘ where id=2;
6.10 對錶中的資料進行刪除的操作 delete from mytable where id=3;
6.11 查詢去除重複的資料
select distinct * from mytable;
6.12 查詢的時候設定別名
select name as kkk from mytable;
6.13 在查詢語句裡面可能寫運算子
create table mytable(
id int,
name varchar;
che int ,
math int ,
ength int
)
6.13.1 查詢表裡面math成績大於40的人 select * from mytables where math>40;
6.13.2 查詢表裡面math成績為10和40的學生
select* from mytables where math int(10,40);
6.13.3 模糊查詢
select*from mytables where name like ‘%lili%‘ ;
6.13.4 查看當前啟動並執行資料庫
select databaese();
6.14 order by 對查詢的記錄進行排序
6.14.1 select * from mytables order by math asc ; 升序
6.14.2 select * from mytables order by math desc ; 降序
6.15 count() 統計表中有多少條記錄
select count(*) from mytables;
6.16 sum 求和函數
select sum(math) from mytables;
6.17 avg 求平均數函數
select avg (math) from mydatables;
6.18 max min
select max(math),min(nath) from mytables;
6.19 分組的操作
create table orders(
id int,
product varchar(20),
price float
);
insert into orders values(1,‘電視‘,900);
insert into orders values(2,‘洗衣機‘,100);
insert into orders values(3,‘洗衣機‘,100);
insert into orders values(4,‘桔子‘,9);
insert into orders values(5,‘桔子‘,9);
insert into orders values(6,‘手電筒‘,20);
insert into orders values(7,‘手電筒‘,20);
查詢購買了幾類商品,並且每類總價大於100的商品
select * from mytables group by product having sum(price)>100;
6.20 select 語句的書寫規範
select...from ...where ...grout by .. having ..order by ..
7. mysql中的資料 類型 7.1字串型
varchar char
兩者的區別 varchar 的長度是可變的,在使用的時候 必須設定其長度
char 的長度是不可變的,在使用的時候,可以不設定其 長度 ;
7.2大資料類型
blob text
7.3數值型
tinyint smallint int bigin float dooble
7.4 邏輯性 bit
7.5 日期型
date 表示日期的格式
time 表示時間的格式
datetime 即可以表示日期 也可以表示 時間
timestamp 自動產生系統的目前時間,不需要手動添加
8.mysql 中的limit 關鍵字 (1)實現查詢表裡面某幾條記錄,用在系統裡面分頁的操作
(2)limit關鍵字不是標準sql的關鍵字,只能在mysql裡面使用
* 在其他的資料庫也有特有關鍵字
比如在oracle裡面實現分頁使用關鍵字 rownum
在sqlserver裡面實現分頁的關鍵字 top
(3)limit關鍵字查詢前幾條記錄 limit 2
* 練習:查詢orders表裡面的前三條記錄
select * from orders limit 3;
select * from orders limit 0,3;
(4)limit關鍵字可以查詢第一條到第幾條記錄 limit 加兩個參數,用逗號隔開
* 練習:查詢orders表裡面第二條到第四條記錄
select * from orders limit 1,3
* 在limit裡面有兩個參數 limit 2,4
** 第一個參數表示記錄的開始位置,但是開始位置從0開始
** 第二個參數從開始位置擷取幾條記錄
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
mysql的入門基礎操作