資料庫學習知識總結

2021-06-25 20:39:13 字數 1215 閱讀 5836

資料庫的常用基本語句:

資料庫:create database ~~     

drop database ~~

alter database ~~

資料表:create table ~~

drop table ~~

alter table ~~

檢視:   create view ~~

drop view ~~

alter view ~~   

以下是常用的各種約束:

主鍵約束(primary key constraint)

要求主鍵列唯一,並且不允許為空

唯一約束(unique constraint)

要求該列唯一,允許為空,但只能出現乙個空值

檢查約束(check constraint)

某列取值範圍限制,格式限制等

預設約束(default constraint)

某列的預設值

外來鍵約束(foreign key constraint)

用於兩表之間建立關係,需要指定引用主表的那一列

1,新增約束

alter

table 表名

addconstraint  約束名 約束型別 具體的約束型別 

---新增主鍵約束   

alter table s

add constraint pk_sno primary key(sno)

---新增唯一約束

alter table s

add constraint uq_sno unique(sno)

---新增預設約束

alter table s

add constraint df_saddress default('位址不詳') for saddress

---新增檢查約束

alter table s

add constraint ck_sbirth check(sbirth between 15 and 40)

---新增外來鍵約束

alter table sc

add constraint fk_sno foreign key(sno) references s(sno)

2,刪除約束

alter table 表名 drop contraint 約束名

資料庫知識總結

這是我關於之前學習資料庫一些知識的總結 首先資料庫分為兩種,關係型資料庫,如mysql,還有非關係型資料庫,如nosql。這裡主要是對比較常用的關係型資料庫進行的總結。關係型資料庫是基於關係代數理論的,它的優缺點 優點 健壯性強,社群龐大 缺點 表結構不直觀,實現複雜,速度慢 join會做乙個笛卡爾...

資料庫知識總結

1.資料庫的基本概念 2.mysql資料庫軟體 安裝解除安裝 配置3.sql 1.資料庫的英文單詞 database 簡稱 db 2.什麼是資料庫?3.資料庫的特點 持久化儲存資料。其實資料庫就是乙個檔案系統 方便儲存和管理資料 使用了統一的方式運算元據庫 sql 4.常見的資料庫軟體 mysql的...

mysql 資料庫學習知識總結4

修改資料表 新增單列 新增多列 只能為資料表下方 alter table tb name add col namecol definition,刪除資料列 刪除多列 alter table tb name drop col name,drop col name 刪除一列同時新增一列資料 中間通過逗號...