資料庫的資料更新操作講解

2021-12-30 01:20:12 字數 920 閱讀 9938

sql的資料插入語句 insert 通常有兩種形式,插入元祖和插入子查詢結果,後者可以一次插入多個元祖

插入元祖

插入乙個新學生元祖

insert

into student//可以列出屬性名,順序可以不同,但是values要與屬性名次序一一對應

values ('16999010','梅西','男',30,'cs');插入一條選課記錄

insert

into sc//可以寫:sc(sno,cno),新插入的記錄沒有值時自動賦空值null

values ('16999010','1',null)插入子查詢結果

暫無1.將學生 16999010 的年齡改為22歲

update student

set sage=22

where sno='16999010';2.將所有學生的年齡增加1歲

update student

set sage=sage+1;3.將計算機系全體學生的成績置零

update sc

set grade=0

where sno in

(select sno

from student

where sdept='cs'

);1.刪除學號為 16999010 的學生記錄

delete

from student

where sno='16999010';2.刪除所有的學生選課記錄

delete

from sc;//將使 sc 成為空表,刪除了 sc 的所有元組3.刪除計算機系所有學生的選課記錄

delete

from sc

where sno in

(select sno

from student

where sdept='cs'

);

MongoDB資料庫索引操作講解

索引就是用來加速查詢的。資料庫索引與書籍的索引類似 有了索引就不需要翻遍整本書,資料庫則可以直接在索引中查詢,使得查詢速度能提高幾個數量級。在索引中找到條目以後,就可以直接跳轉到目標文件的位置。一 建立索引 ensureindex 語法結構 db.collection.ensureindex key...

python操作Mysql資料庫 更新資料

更新批量資料時,如果選擇用insert into on duplicate update的方法,要確保更新的資料中主鍵沒有null資料,如果表中有這樣的資料存在,在讀取資料時要把主鍵是null的過濾掉 python 的execute和executemany都可操作update語句,其中execute...

資料庫 資料更新

資料庫更新操作有三種 在表中新增若干行資料 修改表中的資料和刪除表中的若干行資料。sql中有三類相應的語句,分別是插入資料 insert 修改資料 update 刪除資料 delete insert values 插入單行或多行元組資料 例 向資料庫mysql test的表customers中插入這...