07年自考“數(shù)據(jù)庫及其應(yīng)用Foxpro”實(shí)驗(yàn)題(2)

字號:

第2組實(shí)驗(yàn)題
    現(xiàn)有關(guān)于倉庫管理數(shù)據(jù)庫的模式如下:
    倉庫(倉庫號,面積,地址,管理員)
    貨物(貨號,貨物名,單價(jià),重量)
    存放(倉庫號,貨物號,數(shù)量)
    倉庫與貨物是多對多聯(lián)系。一個(gè)倉庫只設(shè)一名管理員。
    要求完成如下操作:
    1.按題目要求建立表結(jié)構(gòu),各表各個(gè)字段的名字、數(shù)據(jù)類型、長度等根據(jù)語義和查詢的需要自行決定。根據(jù)查詢需要建立索引。(15分)
    答:見第2組實(shí)驗(yàn)題答案文件夾。
    2.利用你所熟悉的方法向各表錄入適量的、滿足題目需要的數(shù)據(jù)。各數(shù)據(jù)項(xiàng)的取值范圍應(yīng)該合理、有效,并與查詢要求相呼應(yīng)。(10分)
    答:見第2組實(shí)驗(yàn)題答案文件夾。
    3.編寫一個(gè)菜單程序。水平菜單項(xiàng)為:錄入、刪除、修改、查詢。要求選擇前三個(gè)菜單項(xiàng)后分別執(zhí)行程序p_insert.prg、p_delete.prg和p_update.prg;選擇查詢菜單項(xiàng)后彈出下級菜單,其菜單項(xiàng)為:順序查詢、索引查詢。(20分)
    答:程序清單如下
    set talk off
    clear
    define menu caidan
    define pad luru of caidan prompt “錄入”
    define pad shanchu of caidan prompt “刪除”
    define pad xiugai of caidan prompt “修改”
    define pad chaxun of caidan prompt “查詢”
    on selection pad luru of caidan do p_insert.prg
    on selection pad shanchu of caidan do p_delete.prg
    on selection pad xiugai of caidan do p_update.prg
    on pad chaxun of caidan activate popup popchaxun
    define popup popchaxun
    define bar 1 of popchaxun prompt “順序查詢”
    define bar 2 of popchaxun prompt “索引查詢”
    activate menu caidan
    set talk on
    return
    4.用FoxPro語言或SQL語言編寫程序完成以下查詢。(以下三題依次為15分、20分、20分)
    (1)列出倉庫清單,要包含所有倉庫的所有屬性,且在最后一行顯示:
    所有倉庫的總面積為 xxxxx平方米。
    答:程序清單如下
    set talk off
    clear
    use 第2組實(shí)驗(yàn)題答案文件夾\cangku
    sum all 面積 to s1
    list off
    ? “ 所有倉庫的總面積為”+str(s1,10,2)+“平方米”
    use
    set talk on
    return
    (2)列出各個(gè)倉庫的庫存情況清單,包括的數(shù)據(jù)項(xiàng)為倉庫號、貨號、貨物名、(每種)貨物的總價(jià)。重量小于50千克的貨物不在其內(nèi)。以倉庫號為第一序、貨號為第二序,升序排列。
    答:程序清單如下
    set talk off
    clear
    select a.倉庫號 as 倉庫號,a.貨號 as 貨號,b.貨物名 as 貨物號,b.單價(jià)*a.數(shù)量_kg as 貨物總價(jià);
    from 第2組實(shí)驗(yàn)題答案文件夾\cunfang a, 第2組實(shí)驗(yàn)題答案文件夾\huowu b;
    where (a.貨號=b.貨號) and (a.數(shù)量_kg>=50);
    order by a.倉庫號,a.貨號;
    into table 第2組實(shí)驗(yàn)題答案文件夾\kuncun
    use 第2組實(shí)驗(yàn)題答案文件夾\kuncun
    list off
    close databases
    set talk on
    return
    (3)列出每個(gè)倉庫的倉庫號,以及每個(gè)倉庫單位面積內(nèi)所承受的平均重量,并按平均承重值從大到小排序。
    答:程序清單如下
    set talk off
    clear
    select a.倉庫號 as 倉庫號,sum(c.數(shù)量_kg*b.重量_kg) as 總重量,a.面積 as 面積;
    from 第2組實(shí)驗(yàn)題答案文件夾\cangku a, 第2組實(shí)驗(yàn)題答案文件夾\huowu b,;
    第2組實(shí)驗(yàn)題答案文件夾\cunfang c;
    where a.倉庫號=c.倉庫號 and c.貨號=b.貨號;
    group by a.倉庫號;
    into cursor tmp
    select tmp.倉庫號 as 倉庫號,tmp.總重量/tmp.面積 as 平均承重;
    from tmp;
    into table 第2組實(shí)驗(yàn)題答案文件夾\pjchzh
    close databases
    use 第2組實(shí)驗(yàn)題答案文件夾\pjchzh
    index on -平均承重 to 第2組實(shí)驗(yàn)題答案文件夾\pjchzh1
    list off
    use
    set talk on
    return