五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

數(shù)據(jù)庫原理與應(yīng)用(10)數(shù)據(jù)操作、視圖、索引

2022-05-28 13:27 作者:洛溪い  | 我要投稿

【數(shù)據(jù)操作】

(1)數(shù)據(jù)庫備份操作。

這里以Navicat舉例。

第一步:雙擊打開對應(yīng)數(shù)據(jù)庫,點(diǎn)擊“備份”。

1

第二步:“新建備份”——“備份”

2

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

插入單行記錄的insert語句的格式為:insert into <表名> (<列名>) values (對應(yīng)列的值)

【例1】將以下數(shù)據(jù)插入到j(luò)xgl數(shù)據(jù)庫中的teachers表中。

舉例

insert into teachers (tno,tname,ps,tbirthday,tdept,tsex) values (001,'譚浩強(qiáng)','教授','1958-01-01','計科','男');

insert into teachers values (001,'譚浩強(qiáng)','教授','1958-01-01','計科','男');

*注:

(1)如果插入的數(shù)據(jù)是嚴(yán)格按照列名順序排列的,可以不寫列名。

(2)中文、英語等文本或日期需要用英文單引號引起來,數(shù)字和空值不用。

【例2】將以下數(shù)據(jù)插入到j(luò)xgl數(shù)據(jù)庫中的sc表中。

舉例

insert into sc (sno,cno,score,point) values (1401102,0000045,null,null);

下面是一個例子,舉例一次性插入多條數(shù)據(jù)的方法:

舉例

(3)復(fù)制表結(jié)構(gòu)及數(shù)據(jù)。

復(fù)制表中的數(shù)據(jù)至新表按照以下格式編寫語句:

create table student_copy1 as select * from students;

復(fù)制表格式至新表按以下格式編寫語句:

create table students_copy2 like students;

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

普通更新數(shù)據(jù)按以下格式編寫語句:

update goods set price=price+1;?

帶條件更新數(shù)據(jù)按以下格式編寫語句:

update goods set price=6 where gname='牛奶餅干';

一次更新多條數(shù)據(jù)按以下格式編寫語句:

update students set sname='王一', bday='1999-10-02' where sno='1801102';

跨表修改數(shù)據(jù)按以下格式編寫語句:

update sc set score=60 where sno in (select sno from students where sname='陳紅');

帶函數(shù)修改數(shù)據(jù)按以下格式編寫語句:

update sale set btime=now(), number=1 where vno in (select vno from vip where vname='陸以寧');

多表連接修改數(shù)據(jù)按以下格式編寫語句:

update sale,vip set?btime=now(), number=1 where sale.vno=vip.vno and vname='陸以寧';

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

刪除所有記錄按以下格式編寫語句:

delete from students;

刪除符合條件的記錄按以下格式編寫語句:

delete from students where sno='1911203';

多表連接刪除數(shù)據(jù)按以下格式編寫語句:

delete sale.* from sale where sale.vno=vip.vno and vname='陸以寧';


【視圖】

視圖是有從基本表中選取出來的數(shù)據(jù)組成的邏輯窗口,是基本表的部分行和列數(shù)據(jù)的組合。

視圖是一個虛表。視圖具有簡單性、安全性、邏輯數(shù)據(jù)獨(dú)立性。

數(shù)據(jù)庫中只存儲視圖的定義,而不存儲視圖所包含的數(shù)據(jù)。

單源表視圖一般可看可改。

創(chuàng)建視圖按以下格式編寫語句:

create view Vgoods2 as select * from goods where price>10 with check option;


【索引】

索引分單列索引和組合索引。單列索引,即一個索引只包含單個列,一個表可以有多個單列索引,但這不是組合索引。組合索引,即一個索引包含多個列。

創(chuàng)建索引時,你需要確保該索引是應(yīng)用在 SQL 查詢語句的條件(一般作為 WHERE 子句的條件)。

實際上,索引也是一張表,該表保存了主鍵與索引字段,并指向?qū)嶓w表的記錄。

CREATE INDEX indexName ON table_name (column_name)

數(shù)據(jù)庫原理與應(yīng)用(10)數(shù)據(jù)操作、視圖、索引的評論 (共 條)

分享到微博請遵守國家法律
阳朔县| 揭阳市| 曲松县| 新竹市| 望谟县| 贡山| 双流县| 高台县| 肃北| 娱乐| 齐河县| 夏邑县| 于田县| 伊宁县| 哈密市| 白银市| 万安县| 格尔木市| 通州区| 马边| 临夏县| 兴仁县| 滨海县| 惠来县| 玛纳斯县| 乐清市| 舞钢市| 大田县| 英山县| 平潭县| 吴川市| 姜堰市| 茂名市| 弋阳县| 西峡县| 侯马市| 大英县| 五大连池市| 新晃| 兰考县| 大埔区|