-
語句以;分號(hào)結(jié)尾
查看全部 -
數(shù)據(jù)庫類型:關(guān)系型數(shù)據(jù)庫、非關(guān)系型數(shù)據(jù)庫
什么是關(guān)系型數(shù)據(jù)庫?
以表的形式存儲(chǔ)數(shù)據(jù),表與表之間可以有很多復(fù)雜的關(guān)系
什么是非關(guān)系型數(shù)據(jù)庫?
以數(shù)據(jù)集的關(guān)系存儲(chǔ)數(shù)據(jù),大量的數(shù)據(jù)集中存儲(chǔ)在一起查看全部 -
foreign key: 外鍵約束---如果一張表中的一個(gè)字段指向了另一張表中的主鍵,就將該字段叫做外鍵;外鍵的數(shù)據(jù)類型必須和指向的主鍵一致;定義外鍵的表稱為從表,被外鍵引用的表稱為主表
create table if not exists user(
????id int unsigned primary key auto_increment,
????username varchar(20) not null
)
desc user;
create table if not exists dynamic(
????id int unsigned primary key auto_increment,
????content varchar(255) not null,
????user_id int unsigned
)
?
create table if not exists dynamic_1(
????id int unsigned primary key auto_increment,
????content varchar(255) not null,
????user_id int unsigned,
????foreign key(user_id) references user(id)
)
create table if not exists dynamic_2(
????id int unsigned primary key auto_increment,
????content varchar(255) not null,
????user_id int unsigned,
????foreign key(user_id) references user(id) on update cascade on delete set null
)
查看全部 -
SQL約束
SQL約束:
primary key:主鍵約束? ?--- 1、區(qū)分記錄的唯一性;2、值不能重復(fù)也不能為空;3、一張表中只能有一個(gè)主鍵;4、同時(shí)將多個(gè)字段作為一個(gè)主鍵來使用,多個(gè)字段聯(lián)合起來的值不能重復(fù)
????????例:?
????????create table if not exists stu1 (
????????????id int unsigned primary key,
????????????name varchar(20)
?????????)
????????create table if not exists stu2 (
????????????id int unsigned,
????????????name varchar(20),
????????????primary key(id)
?????????)
????????create table if not exists stu2 (
????????????id int unsigned,
????????????name varchar(20),
????????????primary key(id,name)
?????????)
auto_increment:自動(dòng)遞增
????create table if not exists stu6 (
????????????id int unsigned primary key auto_increment,
????????????name varchar(20),
?????????)
unique: 唯一約束: 1、保證某個(gè)字段值永遠(yuǎn)不重復(fù);2、允許多個(gè)NULL值存在;3、一張表中只能有一個(gè)主鍵,但是可以有多個(gè)unique
????????create table if not exists stu7 (
????????????id int unsigned?primary key?auto_increment,
????????????name varchar(20) unique,
?????????)
not null:非空約束
????????create table if not exists stu8 (
????????????id int unsigned?primary key?auto_increment,
????????????name varchar(20)? not null,
?????????)
default:默認(rèn)值
????????create table if not exists stu9 (
????????????id int unsigned?primary key?auto_increment,
????????????name varchar(20)??not null,
????????????gender enum('男', '女', '保密') default '保密'
????????????createdAt timestamp default current_timestamp
????????????updateAt?timestamp default current_timestamp on update?current_timestamp
?????????)
foreign key:外鍵約束
????
查看全部 -
查詢數(shù)據(jù)表(查)--查找當(dāng)前使用的數(shù)據(jù)庫
select database()
選擇數(shù)據(jù)庫
use demo
查看當(dāng)前數(shù)據(jù)庫中的所有表
show? tables
查看表結(jié)構(gòu)
desc student;?
創(chuàng)建數(shù)據(jù)表(增)
create table if not exists student (
id int unsigned,
name varchar(20)
age tinyint unsigned
gender enum('男','女','保密')
createAt timestamp
)
已存在才刪除表
drop table if exist student
修改數(shù)據(jù)表
alter table student rename to stu?修改表名
添加字段
alter table student add updatedAt? timestamp
刪除字段
alter? table student drop updateAt
修改字段的數(shù)據(jù)類型
alter talbe student modify createdAt datetime
修改字段的名稱和數(shù)據(jù)類型
alter table student change?createdAt??createAt? timestamp
查看全部 -
SQL數(shù)據(jù)類型:
什么是SQL數(shù)據(jù)類型?
數(shù)字、字符串、日期時(shí)間等類型
為什么需要數(shù)據(jù)類型?
告訴數(shù)據(jù)庫以多大的儲(chǔ)存空間儲(chǔ)存數(shù)據(jù)
合理分配儲(chǔ)存空間
常見的SQL數(shù)據(jù)類型有哪些?
數(shù)字類型:整型、浮點(diǎn)型、定點(diǎn)型等
字符串類型:字符型、文本型、枚舉型、集合型等
日期時(shí)間類型:日期型、日期時(shí)間型、時(shí)間戳型等
整數(shù)類型:
專門用來保存整數(shù)
區(qū)分有符號(hào)和無符號(hào),默認(rèn)是有符號(hào)的(有符號(hào)可以表示負(fù)數(shù),無符號(hào)不能表示負(fù)數(shù))
可以在數(shù)據(jù)類型后加上unsigned表示無符號(hào)
查看全部 -
show databases;? ?顯示所有的數(shù)據(jù)庫
select database(); 選擇使用的數(shù)據(jù)庫
use demo;使用demo數(shù)據(jù)庫
create database demo;? 創(chuàng)建一個(gè)數(shù)據(jù)庫(如果數(shù)據(jù)庫存在就會(huì)報(bào)錯(cuò))
create database demo if not exists demo; 創(chuàng)建數(shù)據(jù)庫(如果數(shù)據(jù)庫存在就不會(huì)創(chuàng)建,否則就創(chuàng)建數(shù)據(jù)庫)推薦使用這種方式創(chuàng)建數(shù)據(jù)庫
drop database demo; 刪除數(shù)據(jù)庫(如果存在就刪除,否則就會(huì)報(bào)錯(cuò))
drop database if exists demo; 刪除數(shù)據(jù)庫(如果存在就刪除,不存也不會(huì)報(bào)錯(cuò))推薦使用這種方式
alter database demo character set utf8mb4 collate utf8mb4_0900_ai_ci;
utf8mb4 :字符集,兼容utf8,且比utf8 能表示更多的字符
utf8mb4_0900_ai_ci:字符集對(duì)應(yīng)的排序規(guī)則,聲調(diào)/重音不敏感(accent insensitive),大小寫不敏感(case insensitive)
查看全部 -
SQL規(guī)范
查看全部 -
記錄知識(shí)點(diǎn)
查看全部 -
--?顯示所有數(shù)據(jù)庫 show?databases; --?查看當(dāng)前使用的數(shù)據(jù)庫 select?database(); --?使用數(shù)據(jù) use?mydemo; --?創(chuàng)建一個(gè)叫“mydemo”的數(shù)據(jù)庫 create?database?mydemo; --?查詢是否存在一個(gè)叫“mydemo”的數(shù)據(jù)庫,沒有的話創(chuàng)建 create?database?if?not?exists?mydemo; --?刪除數(shù)據(jù)庫 drop?database?mydemo; --?查詢是否存在這個(gè)數(shù)據(jù)庫,存在刪除 drop?database?if?exists?mydemo; --?修改數(shù)據(jù)庫“字符集”與“排序規(guī)則” alter?database?mydemo?character?set?utf8mb4?collate?utf8mb4_0900_ai_ci; --?utf8mb4:?字符集,兼容utf8,且比utf8能表達(dá)更多的字符 --?utf8mb4_0900_ai_ci:字符集對(duì)應(yīng)的排序規(guī)則,聲調(diào)/重音不敏感,大小寫不敏感
查看全部 -
配置path環(huán)境變量設(shè)置,方便cmd指令直接運(yùn)行
新建path變量地址
查看全部 -
查看當(dāng)前數(shù)據(jù)庫
Select database
查看全部 -
顯示所有數(shù)據(jù)庫
Show database;
查看全部 -
show database
查看全部 -
什么是數(shù)據(jù)庫
存儲(chǔ)和管理數(shù)據(jù)的倉庫,本質(zhì)上就是一個(gè)軟件。
存儲(chǔ)和管理:對(duì)數(shù)據(jù)的增,刪,改,查。
數(shù)據(jù)庫分為
關(guān)系型數(shù)據(jù)庫
非關(guān)系型數(shù)據(jù)庫
關(guān)系型數(shù)據(jù)庫
是以表的形式存儲(chǔ)數(shù)據(jù),表與表之間可以有很多復(fù)雜關(guān)系
MySQL,Oracle,SQL Server等
非關(guān)系型數(shù)據(jù)庫
以數(shù)據(jù)集的方式存儲(chǔ)數(shù)據(jù),大量的數(shù)據(jù)集中存儲(chǔ)在一起
MongoDB,Redis,Memcached等
什么是MySQL
關(guān)系型數(shù)據(jù)庫
免費(fèi)開源的,也是最受歡迎的數(shù)據(jù)庫之一
查看全部 -
查看全部
-
一、什么是數(shù)據(jù)庫
1. 定義:
數(shù)據(jù)庫本質(zhì)上為用來存儲(chǔ)和管理數(shù)據(jù)的軟件
2. 類型:
2.1 關(guān)系型數(shù)據(jù)庫:
????? 表形式存儲(chǔ)數(shù)據(jù),表和表之間可建立關(guān)系
2.2 非關(guān)系型數(shù)據(jù)庫:
????? 數(shù)據(jù)集中在一起方式存儲(chǔ)數(shù)據(jù),非表形式
二、什么是MySQL
以表形式,持久存儲(chǔ)和管理數(shù)據(jù)的,關(guān)系型數(shù)據(jù)庫查看全部 -
SQL約束,主表從表
查看全部 -
SQL約束
查看全部
舉報(bào)