第四章 DML,DDL和DCL語言

2021-10-01 17:50:05 字數 2024 閱讀 8073

資料的插入

單行插入

insert into table1 (列名) values (列值);

insert into table1 (列名) set (列值);

多行插入

inset into table1 (列名) values (列值),(列值);注:

資料的修改

單個表update table1 set 列名a = 列值a,列名b = 列值b where 條件列式;

多表(一定要連線條件,不然你的條件列式如果只關於乙個表只能限制乙個表,那麼另乙個表可能會成為全表修改,如果用and則表示要兩個條件成立,會修改)

update table1 as a,table2 as b set a.列名a=列值a1,a.列名b = 列值a2

where 連線條件 and 條件列式

資料的刪除

單個表delete from table where 條件列式

多表delete a,b from table1 as a,table2 as b where 連線列式 and 條件列式

truncate table ;

刪除庫drop tablebase if exists 庫名

建立庫create tablebase if not exists 庫名

常規建立

drop tablebase if exists 庫名

create tablebase 庫名

表的建立

刪除表drop table if exists 表名

建立表create table if not exists 表名

常規建立

drop table if exitsts 表名

create table 表名

表的修改

– 修改列結構

alter table 表名 modify 列名 型別 約束 備註

– 修改列名

alter table 表名 modify 列名 新列名 型別 約束 備註

– 修改表名

alter table 表名 rename to 新錶名

表的刪除

drop table if exists 表名

表的複製

– 複製table2的結構到table

create table like table2;

–複製table2 的結構和資料到table(也可以是部分結構和資料)

acid特性

a: 原子性 : 事務裡面的事件要麼全部執行成功要麼全部執行失敗,保持完整性,不可能部分執行;

c: 一致性:事務進行修改前後資料要是完整的,即沒有憑空產生或缺失的資料量;要保證資料修改都有**

i: 隔離性:事務和事務之間要互不影響

d:永續性:事務提交成功後是持久化在資料庫的,即是永久影響資料的,除非回滾

事務開啟和關閉

set autocommit = 0; // 關閉自動提交

start transaction; // 開啟新事務

commit; //提交

rollback; // 回滾

為設定事務級別併發下產生的問題

髒讀: 事務讀取到了另乙個事務未提交的資料

不可重複讀: 乙個事務在內部事件兩次讀同一資料不一樣;這是由於被其他事務修改

幻讀:乙個事務讀取資料,發現條數修改了或為

為了在多個事務併發處理資料的時候保證資料的安全,所以設定隔離級別

隔離級別

read uncommitted 讀未提交

read committed 讀提交

repeatable read 可重複讀

serializable 序列化

隔離級別檢視和修改

select @@tx_isolation;

set @@tx_isolatin = read uncommitted;

set transaction isolation set read committed;

set global transaction isolation set serializable;

C語言第四章

4.2 用if語句實現選擇結構 4.2.1 用if語句處理選擇結構舉例 4.5條件運算子和條件表示式 4.6 選擇結構的巢狀 4.7用switch語句實現多分支選擇結構 4.8 選擇結構程式綜合舉例 4.1 選擇結構和條件判斷 4.2 用if語句實現選擇結構 4.2.1 用if語句處理選擇結構舉例 ...

C語言第四章

main.c project1 created by sihan guo on 2019 06 13.include include int main int argc,const char ar 構成復合語句 所以要把這個括起來 int x 6 if x 5 b if 表示式 語句1 else 語...

C語言 第四章(1)

1.null 字元 陣列末尾位置的字元 0 陣列結尾一定是以 0結束 空字元符號是 include int main int i printf d sizeof n n中所佔長度為6,也就是說編譯器自動在最後補了一位 0 當n定義了長度,編譯器則會在長度沒有超過宣告時寫入 02.strlen和siz...