國家開放大學(xué)電大《MySQL數(shù)據(jù)庫應(yīng)用》網(wǎng)絡(luò)核心課實(shí)驗(yàn)訓(xùn)練1及3答案_第1頁
國家開放大學(xué)電大《MySQL數(shù)據(jù)庫應(yīng)用》網(wǎng)絡(luò)核心課實(shí)驗(yàn)訓(xùn)練1及3答案_第2頁
國家開放大學(xué)電大《MySQL數(shù)據(jù)庫應(yīng)用》網(wǎng)絡(luò)核心課實(shí)驗(yàn)訓(xùn)練1及3答案_第3頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、最新國家開放大學(xué)電大MySQL數(shù)據(jù)庫應(yīng)用網(wǎng)絡(luò)核心課實(shí)驗(yàn)訓(xùn)練1及3答案盜傳必究本課程分為形成性考核和終結(jié)性末考兩種考核形式,形成性考核占50% (滿分100分),末考為網(wǎng)絡(luò)考試占 50% (滿分100),其中形成性考核為完成課程網(wǎng)站上的形考作業(yè)任務(wù),形考作業(yè)均為主觀題,包括四個(gè)實(shí) 訓(xùn):實(shí)訓(xùn)一:在MYSQL創(chuàng)建數(shù)據(jù)庫和表,25分;實(shí)訓(xùn)二:數(shù)據(jù)查詢操作,25分;實(shí)訓(xùn)三:數(shù)據(jù)增刪改操 作,25分;實(shí)訓(xùn)四:數(shù)據(jù)庫系統(tǒng)維護(hù),25分。實(shí)驗(yàn)訓(xùn)練1在MySQL中創(chuàng)建數(shù)據(jù)庫和表答案:步驟:1、使用show語句找出在服務(wù)器上當(dāng)前存在什么數(shù)據(jù)庫:mysql>show databases;Fiysql> s

2、how databases ; Database i infornation_schena i nysqli perfornance_schena i sakilai sns;world板 rows in set <0.00 sec>2、創(chuàng)建一個(gè)數(shù)據(jù)庫test :mysql>create database test;mysql> create database test; Query 0K> 1 row affected <0.00 sec>3、選擇你所創(chuàng)建的數(shù)據(jù)庫:mysql>use test;nysql> use test; datab

3、ase changed4創(chuàng)建一個(gè)數(shù)據(jù)表:首先查看剛才創(chuàng)建的數(shù)據(jù)庫中存在什么表: mysql>show tables;uysql> show tables; Empty set <0.00 sec>(說明剛才創(chuàng)建的數(shù)據(jù)庫中還沒有數(shù)據(jù)庫表)接著我們創(chuàng)建一個(gè)關(guān)于students的數(shù)據(jù)表:包括學(xué)生的學(xué)號(hào)(id),姓名(name),性別(sex),年 齡(age) omysql>create table students(id int unsigned not null auto_increment primary key, name char(8) not null,se

4、x char(4) not null, age tinyint unsigned not null,);nysql> create table students<id int unsigned not null auto_increnent primary key .name char<8> not nullsex char<4> not nullage tinyint unsigned not null> ; Query OK. 0 rov/s affected <0.39 sec>解釋:以"id int unsigned no

5、t null auto_increment primary key"行進(jìn)行介紹:"id”為列的名稱;"int”指定該列的類型為int(取值范圍為-8388608到8388607),在后而我們又用"unsigned” 加以修飾,表示該類型為無符號(hào)型,此時(shí)該列的取值范圍為0到16777215;"not null"說明該列的值不能為空,必須要填,如果不指定該屬性,默認(rèn)可為空;/?auto_incrementz/需在整數(shù)列中使用,其作用是在插入數(shù)據(jù)時(shí)若該列為NULL, MySQL將自動(dòng)產(chǎn)生 一個(gè)比現(xiàn)存值更大的唯一標(biāo)識(shí)符值。在每張表中僅能有一個(gè)

6、這樣的值旦所在列必須為索引列。''primary key”表示該列是表的主鍵,本列的值必須唯一,MySQL將白動(dòng)索引該列。下而的char(8)表示存儲(chǔ)的字符長(zhǎng)度為8, tinyint的取值范圍為-127到128, default屬性指 定當(dāng)該列值為空時(shí)的默認(rèn)值。創(chuàng)建一個(gè)表后,用show tables顯示數(shù)據(jù)庫中有哪些表:mysql>show tables ;nysql> show tables; 4I Tables_in_test i4I studentsI<1 row in set <0.00 sec>5、顯示表結(jié)構(gòu):mysql>descr

7、ibe students;>ysql> describe students ;! Field : Type; Null ; Key : Default : ExtraI idiint<10>unsigned;NO; PRI ;NULL; auto_increment ;name;char<8>:NOI;NULL:!;sex;char<4>:NO:;NULL:;age;tinyint<3>unsigned ;NO;NULL;I rows in set <0.04 sec>6、在表中添加記錄:首先用select命令來查看表中的

8、數(shù)據(jù):mysql>select*from students;select*fron students; Empty set <0.00 sec>(說明剛才創(chuàng)建的數(shù)據(jù)庫表中還沒有任何記錄)接著加入一條新紀(jì)錄:mysql>insert into students value( 01,' Tom' , ' F' , ' 18');iysql> insert into students ualue<JI9 Tom'.'F'.'18'; Juery OK. 1 row affect

9、ed <0.07 sec>再用select命令來查看表中的數(shù)據(jù)的變化:mysql>select*from students;7、用文本方式將數(shù)據(jù)裝入一個(gè)數(shù)據(jù)庫表:創(chuàng)建一個(gè)文本文件“ student, sql每行包括一個(gè)記錄,用TAB鍵把值分開,并且以在create table語句中列出的次序,例如:02 Tony F 1803 Amy M 1804 Lisa M 18將文本文件“student, sql ”裝載到students表中:mysql>load data local infile” e:student. sql" into table student

10、s;lmysql> load data local inf ile,fe: Wstudents .sqlMinto table students ; IQuerv OK. 0 rows affected (0.00 sec>(Records: 3 Deleted: 0 Skipped: 3 Warnings: 0再使用select命令來查看表中的數(shù)據(jù)的變化:mysql>select*from students;mysql>selectfro ni students;,+-夫;id ;nane ;sex iage ;,+-夫+;1 ;Ton iFi i18 :2 :Ton

11、y !Fi i18 :3 :Any iMi i18 :;4 ;Lisa ;Mi i18 :;5 ;1 0i i0 !, . .一+5 rowsin set<0.00sec>實(shí)驗(yàn)訓(xùn)練3數(shù)據(jù)增刪改操作答案:實(shí)驗(yàn)?zāi)康模夯趯?shí)驗(yàn)1創(chuàng)建的汽車用品網(wǎng)上商城數(shù)據(jù)庫Shopping,練習(xí)Insert、Delete. TRUNCATE TABLE. Update 語句的操作方法,理解單記錄插入與批量插入、DELETE與TRUNCATE TABLE語句、單表修改與多表修改的 區(qū)別。實(shí)驗(yàn)內(nèi)容:【實(shí)驗(yàn)3-1插入數(shù)據(jù)(1) 使用單記錄插入Insert語句分別完成汽車配件表Autoparts商品類別表cate

12、gory、用戶表 Client、用戶類別表Clientkind、購物車表shoppingcart、訂單表Order、訂單明細(xì)表 order_has_Autoparts評(píng)論Comment的數(shù)據(jù)插入,數(shù)據(jù)值自定;并通過select語句檢查插入前后的記錄 情況。INSERT INTO 目標(biāo)表 SELECT * FROM 來源表;insert into insertTest select * from insertTest2;INSERT INTO目標(biāo)表(字段1,字段2, .) SELECT字段1,字段2, . FROM來源表;(這里的話字段 必須保持一致)insert into insertTest

13、2(id) select id from insertTest2;INSERT INTO 目標(biāo)表(字段1,字段2,.)SELECT 字段 1,字段 2,.FROM來源表WHERE not exists (select * from 目標(biāo)表where目標(biāo)表.比較字段=來源表.比較字段);!.插入多條記錄:insert into insertTest2(id, name )select id, namefrom insertTestwhere not exists ( select * from insertTest2 where insertTest2. id=insertTest. id);2

14、>.插入一條記錄:insert into insertTest (id, name )SELECT 100, *liudehuaFROM dualWHERE not exists ( select * from insertTest where insertTest. id = 100);(2) 使用帶Select的Insert語句完成汽車配件表Autoparts中數(shù)據(jù)的批量追加;并通過select語句 檢查插入前后的記錄情況。create TABLE Table! ( a varchar( 10 ), b varchar ( 10 ), c varchar ( 10 ), CONSTR

15、AINT PK_Tablel PRIMARY KEY CLUSTERED ( a ASC )ON PRIMARYcreate TABLE Table2 ( a varchar( 10 ), c varchar ( 10 ), d int , CONSTRAINT PK_Table2 PRIMARY KEY CLUSTERED ( a ASC )ON PRIMARY GO【實(shí)驗(yàn)3-2刪除數(shù)據(jù)(1 ) 使用Delete語句分別完成購物車表shoppingcart、訂單表Order、訂單明細(xì)表 Order_has_Autoparts評(píng)論Comment的數(shù)據(jù)刪除,刪除條件自定;并通過select語句檢

16、查刪除前后的記 錄情況。刪除數(shù)據(jù)delete from meta order itemswhere meta_order_items_id in(select b. meta_order_items_id from (- 主意:同一張表要外包這一層視圖select meta_order_items_id from meta_order_itewhere state create'and CREATED_STAMP 2015-ll-19,(2)使用TRUNCATE TABLE語句分別完成購物車表shoppingcart、評(píng)論Comment的數(shù)據(jù)刪除?!緦?shí)驗(yàn)3-3】修改數(shù)據(jù)使用Update分別完成汽車配件表Autoparts商品類別表category用戶表Client用戶類別表 Clientkind、購物車表 shoppingcart、訂單表 Order、訂單明細(xì)表 Order_has_Autoparts 評(píng)論 Comment 的數(shù)據(jù)修改,修改后數(shù)據(jù)值自定,修改條件自定;并通過selec

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論