數(shù)據(jù)庫課程設計說明書 創(chuàng)建和修改表的定義.doc_第1頁
數(shù)據(jù)庫課程設計說明書 創(chuàng)建和修改表的定義.doc_第2頁
數(shù)據(jù)庫課程設計說明書 創(chuàng)建和修改表的定義.doc_第3頁
數(shù)據(jù)庫課程設計說明書 創(chuàng)建和修改表的定義.doc_第4頁
數(shù)據(jù)庫課程設計說明書 創(chuàng)建和修改表的定義.doc_第5頁
已閱讀5頁,還剩20頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

課程設計說明書設計題目: 創(chuàng)建和修改表的定義 _專 業(yè): 計算機科學與技術(shù) 班 級: _設 計 人: _山東科技大學2012年 06月 20 日課程設計任務書學院 信息科學與工程學院 專業(yè) 計算機科學與技術(shù) 班級 姓名一、 課程設計題目:(1) 創(chuàng)建和修改表的定義 二、 課程設計主要參考資料:(1) 數(shù)據(jù)庫系統(tǒng)概論 (2) c語言程序設計 (3) 數(shù)據(jù)結(jié)構(gòu) 三、 課程設計應解決的主要問題:1.選擇一種高級語言實現(xiàn)一個簡單的dbms主要功能: 實現(xiàn):create table (, ) 實現(xiàn):alter table add dropmodify 要求:(1)設計實現(xiàn)表的物理存儲結(jié)構(gòu);(2)語句以命令行和圖形化界面兩種形式實現(xiàn);(3)提交課程設計報告。四、 課程設計相關(guān)附件(如:圖紙、軟件等):(1) (2) (3) 五、 任務發(fā)出日期: 課程設計完成日期: 指導教師簽字: 系主任簽字: 指導教師對課程設計的評語指導教師簽字: 2012年 月 日山東科技大學學生課程設計一、 設計要求:(1)設計實現(xiàn)表的物理存儲結(jié)構(gòu);(2)語句以命令行和圖形化界面兩種形式實現(xiàn);(3)提交課程設計報告。二、 需求分析:1.選擇一種高級語言實現(xiàn)一個簡單的dbms 設計實現(xiàn)表的物理存儲結(jié)構(gòu);語句以命令行和圖形化界面兩種形式實現(xiàn);三、 設計思想:(1) 由命令行輸入sql語句, 通過對語句進行語法分析,分離關(guān)鍵字,語句以分號作為結(jié)束符號; (2) 以 *.txt 文件存放建立的表,一張表對應一個 *.txt 文件;(3) 用戶可直接輸入create table 語句和alter語句, 程序自動解析和查錯, output語句輸出表的相關(guān)信息。四、 主要源程序:/源程序在codeblocks 10.05下運行通過#include#include#include#include#include#include#include#includeusing namespace std;#define max 1000#define n 100/表中每個域的結(jié)構(gòu):struct field char namen; char typen; int len; char conditionn; field() len = 0; name0 = type0 = condition0 = 0; ;/讀入的語句字符串char sqlmax,sqltmpmax;/將輸入的大寫字母轉(zhuǎn)化為小寫字母void tolower(char *s) int len = strlen(s); for(int i = 0; i = a & si = z) si += 32; /讀入sql語句,并進行格式化分離單詞, 以分號結(jié)束, esc退出整個程序int read() char c; int i; for(i = 0; c = getch(); i+) if(c = ;) break; if(c = 27) exit(0); if(c = 8) i -= 2; if(i -1) i = -1; system(cls); printf(:nplease input the sql sentence:nn); for(int j = 0; j tmp; if( 0 != strcmp(tmp,create) error = true; printf(nthe word create maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; int len = strlen(table_name); strcat(table_name, .txt); if(access(table_name, 0) = 0) printf(the table already exist! over it?y/nn); char c; c = getchar(); if(c = n) return false; else remove(table_name); while(true) field field; ss tmp; if(tmp0 = ,) add(field, table_name); continue; if(strcmp(tmp, ;) = 0) break; strcpy(, tmp); if(!(ss tmp) break; if(tmp0 = ,) add(field, table_name); continue; bool flg = false; for(int i = 0; i tmp; if(tmp0 = ,) add(field, table_name); continue; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(tmp0 = ,) add(field, table_name); continue; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); break; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); add(field, table_name); return (!error);/修改表函數(shù)bool alter() char tmpn; char table_namen; bool error = false; char type610= char,int,float,double,time,date; stringstream ss(sql); ss tmp; if( 0 != strcmp(tmp,alter) error = true; printf(nthe word alter maybe error!n); else ss tmp; if(0 != strcmp(tmp,table) error = true; printf(nthe word table maybe error!n); else ss table_name; strcat(table_name, .txt); if(access(table_name, 0) = -1) printf(the table do not exist!n); return false; ss tmp; if(strcmp(tmp, add) = 0) ss tmp; field field; strcpy(, tmp); ss tmp; bool flg = false; for(int i = 0; i tmp; bool flg = true; int len = strlen(tmp); int sum = 0; for(int i = 0; i 58 | tmpi tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 = strcmp(st,key) strcat(tmp, key); strcpy(field.condition, tmp); else error = true; printf(the word key maybe error!n); return false; else if(strcmp(tmp,unique)=0) strcpy(field.condition, tmp); file *fp = fopen(table_name, a); fwrite(&field, sizeof(field), 1, fp); fclose(fp); else if(strcmp(tmp, drop) = 0) ss tmp; if(0 = strcmp(tmp,primary) char stn; ss st; if( 0 != strcmp(st,key) error = true; printf(the word key maybe error!n); return false; else strcat(tmp, key); field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); printf(%dn, len); for(int i = 0; i len; +i) if(strcmp(fieldi.condition, tmp) = 0) fieldi.condition0 = 0; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i tmp; ss tmp; char stn; int sum = 0; ss st; bool flg = false; for(int i = 0; i t; bool flg = true; int len = strlen(t); for(int i = 0; i 58 | ti 48) flg = false; break; else sum = sum * 10 + ti - 0; if(!flg) error = true; printf(nthe length of the type maybe error!n); return false; field fieldn; int len = 0; file *fp = fopen(table_name, r); while(fread(&fieldlen, sizeof(field), 1, fp) != 0) +len; fclose(fp); remove(table_name); for(int i = 0; i len; +i) if(strcmp(, tmp) = 0) strcpy(fieldi.type, st); fieldi.len = sum; break; fp = fopen(table_name, w); fwrite(&field0, sizeof(field), 1, fp); fclose(fp); for(int i = 1; i len; +i) fp = fopen(table_name, a); fwrite(&fieldi, sizeof(field), 1, fp); fclose(fp); return (!error);/輸出表的相關(guān)信息void output(char *s) if(access(s, 0) = -1) printf(the table do not exist!n); return ; printf(*n); printf( name type length conditionn); printf(*n); file *fp = fopen(s, r); field field; while(fread(&field, sizeof(field), 1, fp) != 0) printf(%10s, ); if(field.type0 != 0) printf( %10s, field.type); else printf( ); if(field.len != 0) printf( %10d, field.len); else printf( ); if(field.condition0 != 0) printf( %10s, field.condition); else printf( ); puts(); fclose(fp); printf(*n);/程序主函數(shù),循環(huán)讀入, 直到讀到escint main() while(true) printf(:nplease input the sql sentence:nn); read(); stringstream ss(sql); char sn; ss s; if(strcmp(s, create) = 0) if(create() printf(create successful!n); else printf(create failed!n); else if(strcmp(alter, s) = 0) if(alter() printf(alter successful!n); else printf(alter failedn); else if(strcmp(output, s) = 0) ss s; strcat(s, .txt); output(s); ret

溫馨提示

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

評論

0/150

提交評論