数据库设计源代码.docx

上传人:p** 文档编号:462197 上传时间:2023-09-06 格式:DOCX 页数:73 大小:72.22KB
下载 相关 举报
数据库设计源代码.docx_第1页
第1页 / 共73页
数据库设计源代码.docx_第2页
第2页 / 共73页
数据库设计源代码.docx_第3页
第3页 / 共73页
数据库设计源代码.docx_第4页
第4页 / 共73页
数据库设计源代码.docx_第5页
第5页 / 共73页
数据库设计源代码.docx_第6页
第6页 / 共73页
数据库设计源代码.docx_第7页
第7页 / 共73页
数据库设计源代码.docx_第8页
第8页 / 共73页
数据库设计源代码.docx_第9页
第9页 / 共73页
数据库设计源代码.docx_第10页
第10页 / 共73页
亲,该文档总共73页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《数据库设计源代码.docx》由会员分享,可在线阅读,更多相关《数据库设计源代码.docx(73页珍藏版)》请在第壹文秘上搜索。

1、/选择一种高级语言实现下列语句的功能。/CREATETABLE表名(V列名数据类型歹IJ完整性约束条件习,列名数据/类型列完整性约束条件习ILV表完整性约束条件)/Altertable表名addV新列名数据类型列完整性约束DROPv列完整性约束名习MODIFYV列名V数据类型运用说明1、将程序文件table.sql放在D盘根书目下。2、在C盘根书目下建立一个名为“数据库”的文件夹,用于存储表。3、建立的表存储路径为C:数据库:table.dbf。4、在程序文件table.sql中只有一条建表语句和三条修改表语句,在以程序方式执/行时留意执行的次数,慎重选择“是否接着执行”。5、程序输入的SQL

2、语句格式如下:/createtablestudent/(/SNOintPRIMARYKEY,/SNAMEchar(10)UNIQUE,/SAGEint,/SDEPTchar(20)NOTNULL,/COURSEchar(20),/GRADEint/);/altertablestudentaddCNOintNOTNULL;/altertablestudentaltercolumnSAGEshort;/altertablestudentdropSDEPT;#include#include#include#include/宏定义#defineYEARO#defineMONTH1#defineDAY2

3、#defineFOX_VERISONNFo262#defineMAX40/字段类型#defineDATE0x44#defineDOUBLE0x45#defineFLOAT0x46#defineSHORT0x47#defineINT0x48#defineTRUE1#defineFALSEO/文件头结构体定义structDbfHead(chardbFlag;charyear;charmonth;charday;intrecCounts;shortfirstRecAddr;shortrecLen;charundo20;);*pDbfHead;typedefstructDbfHeadDbfHead,/

4、字段描述结构体定义structFieldDcp(charfieldNamel0;charundo1;charfieldType;shortoffset;charundo22;charfieldLen;charnumDecis;charundo314;);typedefstructFieldDcpFieldDcp,*pFieldDcp;/字段数据结构体定义structDbfFieldchar*fieldData;charfieldNamel0;charfieldType;charfieldLen;charfieldDcis;shortoffset;);typedefstructDbfFieldD

5、bfField,*pDbfField;记录结构体定义structDbfRec(chardelFlag;DbfFieldfieldMAX;intrealCounts;typedefstructDbfRecDbfRec,*pDbfRec;dbf文件句柄定义structDbfHandchar50;DbfHeadheader;DbfRecrec;longcurRecNo;longCurFpAddr;FILE*fd;);typedefstructDbfHandDbfHand,*pDbfHand;约束条件typedefstructConditionintflag;/flag用于区分约束条件(PARIMAR

6、YKEY1UNIQUE2NOTNULL3)Condition;pDbfHandf;DbfRecrec;chartable_name20;charsql300,sql1300;charGetDate(intgetMode)/获得日期(if(DAY=getMode)return01;if(MONTH=getMode)return06;if(YEAR=getMode)return10;elseexit(0);shortGetHeadLength(pDbfRecrec)获得文件头长度(returnrec-realCounts*32+32+2;shortGetRecLength(pDbfRecrec)/

7、获得文件体长度(registerinti=0;intcount=0;for(i=0;irealCounts;i+)if(rec-fieldi.fieldType=,D,)count+=8;continue;elseif(rec-fieldi.fieldType=,)count+=4;continue;elseif(rec-fieldi.fieldType=,T,)count+=6;continue;count+=rec-fieldi.fieldLen;returncount+1;)pDbfHandNewDbfHead(pDbfHandhand,pDbfRecrec)/新建文件intret=-1

8、;hand-header.dbFlag=0x03;hand-header.day=GetDate(DAY);hand-header.month=GetDate(MONTH);hand-header.year=GetDate(YEAR);hand-header.recLen=GetRecLength(rec);hand-header.recCounts=O;hand-header.firstRecAddr=GetHeadLength(rec);if(O!=fseek(hand-fd,O,SEEK.SET)returnNULL;ret=fwrite(char*)&hand-header,Sizeo

9、f(DbfHead),1hand-fd);if(ret!=-1)returnhand;elsereturnNULL;)pDbfHandUpdateHead(pDbfHandhand)/更新文件头(if(O!=fseek(hand-fd,O,SEEK.SET)returnNULL;if(-1=fwrite(char*)&hand-header,Sizeof(DbfHead),1,hand-fd)returnNULL;fclose(hand-fd);returnhand;)pDbfHandWriteFieldDicsribe(pDbfHandhand,pDbfRecrec)/写字段描述部分inti

10、=0;FieldDcpfield=O;field,offset=0x01;for(i=0;irealCounts;i+)(field.fieldType=rec-fieldi.fieldType;field.numDecis=0;switch(field.fieldType)caseDOUBLE:field.fieldLen=8;break;caseFLOAT:field.fieldLen=4;break;caseINT:field.fieldLen=4;break;caseSHORT:field.fieldLen=2;break;default:field.fieldLen=rec-fiel

11、di.fieldLen;break;strcpy(field.fieldName,rec-fieldi.fieldName);field.offset+=(short)rec-fieldi.fieldLen;if(-l=fwrite(char*)sfield,Sizeof(FieldDcp),1,hand-fd)returnNULL;hand-rec.delFlag=0x20;hand-rec.realCounts=rec-realCounts;for(i=0;irealCounts;i+)hand-rec.fieldi=rec-fieldi;returnhand;voidWriteField

12、End(pDbfHandhand)/写文件头结束标记inti=0;charbuf2=OxOD,OxOO;charversionBufFOX_VERISONJNFO=0;if(0=fseek(hand-fd,0,SEEK.END)(if(-1=fwrite(buf,2,1,hand-fd)return;return;pDbfHandReadDbfHead(pDbfHandhand)读文件头信息inti=0,j=0;if(-1!=(fseek(hand-fd,0,SEEK.SET)(if(0!=fread(char*)&hand-header,32,1,hand-fd)returnhand;ret

13、urnNULL;intGetFieldCount(pDbfHandhand)/得至字段个数inti=0;intoffset=1;FieldDcpfield=0;charcEnd=0;for(i=O;ifd,(i+1)*32,SEEK.SET)return-1;if(O!=fread(char*)&field,32,1,hand-fd)fread(&cEnd,l,1,hand-fd);if(OxOD=cEnd)return(i+1);return-1;pDbfHandReadFieldDiscribe(pDbfHandhand)/读字段描述信息inti=0,j=0;intfieldCount=GetFieldCount(hand);hand-rec.realCounts=fieldCount;for(i=0;irec.realCounts;i+)(FieldDcpfield=0;if(-1=fseek(hand-fd,(i+l)*32,SEEK.SET)returnNULL;if(-1=fread(char*)&field,32,1,hand-fd)returnNULL;memcpy(h

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > IT计算机 > 数据结构与算法

copyright@ 2008-2023 1wenmi网站版权所有

经营许可证编号:宁ICP备2022001189号-1

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。第壹文秘仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知第壹文秘网,我们立即给予删除!