數(shù)據(jù)庫

什么是數(shù)據(jù)庫?

數(shù)據(jù)庫(Database):存儲(chǔ)數(shù)據(jù)的倉庫

高效地存儲(chǔ)和處理數(shù)據(jù)的介質(zhì)(介質(zhì)主要是兩種:磁盤和內(nèi)存)

數(shù)據(jù)庫的分類

基于存儲(chǔ)介質(zhì)的不同:分為關(guān)系型數(shù)據(jù)庫(SQL)和非關(guān)系型數(shù)據(jù)庫(NoSQL:Not Only SQL)

不同數(shù)據(jù)庫陣營的產(chǎn)品

關(guān)系型數(shù)據(jù)庫

大型:Oracle、DB2

中型:SQL Server、MySQL

小型:Access、SQLite等

非關(guān)系型數(shù)據(jù)庫:Memcached、MongoDB、Redis

兩種數(shù)據(jù)庫陣營的區(qū)別

關(guān)系型數(shù)據(jù)庫:安全(保存磁盤,基本不可能丟失),容易理解,比較浪費(fèi)空間(二維表)

非關(guān)系型數(shù)據(jù)庫:效率高,不安全(斷電丟失)

什么是關(guān)系型數(shù)據(jù)庫?

是一種建立在關(guān)系模型(數(shù)學(xué)模型)上的數(shù)據(jù)庫

關(guān)系模型:一種所謂建立在關(guān)系上的模型

關(guān)系模型包含三個(gè)方面:

數(shù)據(jù)結(jié)構(gòu):用于解決數(shù)據(jù)存儲(chǔ)的問題,二維表(有行和列)

操作指令集合:所有SQL語句

完整性約束:表內(nèi)數(shù)據(jù)約束(字段與字段)、表與表之間約束(外鍵)

從需要存儲(chǔ)的數(shù)據(jù)需求中分析,如果是一類數(shù)據(jù)(實(shí)體)應(yīng)該設(shè)計(jì)成一張二維表:表是由表頭和數(shù)據(jù)部分組成

表頭:即字段名,用來規(guī)定數(shù)據(jù)的名字

數(shù)據(jù)部分:實(shí)際存儲(chǔ)的數(shù)據(jù)單元

關(guān)系型數(shù)據(jù)庫,需要維護(hù)實(shí)體內(nèi)部、實(shí)體與實(shí)體之間的聯(lián)系

show databases; --查看所有數(shù)據(jù)庫

exit quit \q --退出命令

mysql.exe? -h? localhost -P 3306 -u root -p --進(jìn)入數(shù)據(jù)庫

--創(chuàng)建數(shù)據(jù)庫

create database mydatebase charset utf8;

--關(guān)鍵字?jǐn)?shù)據(jù)庫

create database mydatebase charset utf8;

--中文數(shù)據(jù)庫

create database 中國 mydatebase charset utf8;

--告訴服務(wù)器當(dāng)前中文字符集

set names gbk;

--創(chuàng)建數(shù)據(jù)庫

create database informationest charset utf8;

--查看數(shù)據(jù)庫

show databases;

--查看以information_開始的數(shù)據(jù)庫(_需要被轉(zhuǎn)義)

show databases like 'information\_%';

show databases like 'information\_%'; --相當(dāng)于information%

--查看數(shù)據(jù)庫的創(chuàng)建語句

show create database mydatebase;

show create database ‘database’;--查看帶有關(guān)鍵字?jǐn)?shù)據(jù)庫

--修改數(shù)據(jù)庫

alter database informationtest charset charset utf8;

--刪除數(shù)據(jù)庫

drop database + 數(shù)據(jù)庫名字;

--新增數(shù)據(jù)表

create table if not exists student(

name varchar(10),

gender varchar(10),

number varchar(10),

age int

)charset utf8;

--創(chuàng)建數(shù)據(jù)表

--進(jìn)入數(shù)據(jù)庫

use mydatebase;

--創(chuàng)建表

create table class()charset utf8;

--創(chuàng)建表

create table class(

name varchar(10),

room varchar(10)

)charset utf8;

--查看所有表

show tables;

--查看所有以s結(jié)尾的表、

show tables like'%s';盡量不要用效率低的,不知效率低

--查看表的創(chuàng)建語句

show create table student;

show create table student;\g

show create table student;\G--將查到的結(jié)構(gòu)縱向

--查看表結(jié)構(gòu)

desc class;

describe class;

show columns from class;

--重命名表(student表 --> tb1 my_student)

rename table student to my_student;

--修改表選項(xiàng): 字符集

alter table my_student charset = GBK;

--給學(xué)生表加ID,放到第一個(gè)位置

alter table my_student

add column id int

first;

--將學(xué)生表中的number學(xué)號(hào)字段變成固定長度,且放到第二位(ID之后)

alert table my_student modify number char(10) after id ;

--修改學(xué)生表中的gender字段為sex

alert table my_student change gender sex varchar(10);

--刪除學(xué)生表中的age年齡字段

alert table my_student drop age;

--刪除數(shù)據(jù)表

drop table class;

--插入數(shù)據(jù)

insert into my_student value

(1,'bc20190001','jim','male'),

(2,'bc20190002','lili','female');

--插入數(shù)據(jù),指定字段列表

insert into my_student(number,sex,name,id) value

(1,'bc20190003','male','Tom'),

(2,'bc20190002','female','Lucy');

--查看所有人數(shù)據(jù)

select * from my_student

--查看指定字段,指定條件的數(shù)據(jù)

--查看滿足ID為1的學(xué)生信息

select id,number,sex,name from my_student where id=1;

--更新數(shù)據(jù)

update my_student set sex = 'female' where name='Jim';

--刪除數(shù)據(jù)

delete from my_student where sex='male';

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 什么是數(shù)據(jù)庫? 數(shù)據(jù)庫:database,存儲(chǔ)倉庫的介質(zhì)。 數(shù)據(jù)庫:高效的存儲(chǔ)和處理數(shù)據(jù)的介質(zhì)(介質(zhì)主要是兩種:磁...
    翊溪閱讀 1,123評(píng)論 0 5
  • 數(shù)據(jù)庫可以看作是一個(gè)專門存儲(chǔ)數(shù)據(jù)對(duì)象的容器,這里的數(shù)據(jù)對(duì)象包括表、視圖、觸發(fā)器、存儲(chǔ)過程等,其中表是最基本的數(shù)據(jù)對(duì)...
    黑白色的天空閱讀 969評(píng)論 0 4
  • 數(shù)據(jù)庫基礎(chǔ) 數(shù)據(jù)庫系統(tǒng)概述 數(shù)據(jù)庫技術(shù)的發(fā)展 人工管理階段 特點(diǎn):1.數(shù)據(jù)不保存???2.使用應(yīng)用程序管理數(shù)據(jù)??...
    真不懂事閱讀 908評(píng)論 0 0
  • 數(shù)據(jù)庫的概念和作用 特殊格式數(shù)據(jù)文件的集合就是數(shù)據(jù)庫 我們網(wǎng)頁看到的數(shù)據(jù)展示,其實(shí)在數(shù)據(jù)庫里存儲(chǔ)如上面的顯示 數(shù)據(jù)...
    ca8519be679b閱讀 1,678評(píng)論 0 50
  • 安裝與配置 安裝xampp(為了使用mysql數(shù)據(jù)庫):點(diǎn)擊MySQL的start以啟動(dòng)mysql 配置環(huán)境變量(...
    jxvl假裝閱讀 444評(píng)論 0 0

友情鏈接更多精彩內(nèi)容