2025年增删改查sql语句问题与解决(增、删、改、查 对应的sql语法)

增删改查sql语句问题与解决(增、删、改、查 对应的sql语法)Database Manage System include lt stdio h gt include lt stdlib h gt include lt conio h gt include lt string h gt define MAX SIZE 50 表中所含字段最大长度

大家好,我是讯享网,很高兴认识大家。

/* Database Manage System */

#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h>

#define MAX_SIZE 50 /表中所含字段最大长度/ #define FILE_NAME_LENGTH 15 /文件名最大长度/ #define FIELD_NAME_LENGTH 15 /字段名最大长度/ #define T_EDIT_LENGTH 15 /* Table Edit 长度*/

typedef struct { char sFieldName[FIELD_NAME_LENGTH]; /列名/ char sType[8]; /列类型/ int iSize; /列空间大小/ char bKey; /是否主键/ char bNullFlag; /是否为空/ char bValidFlag; /*是否有效 */ } TableMode,*PTableMode;

void main() { TableMode tempTM; /临时文件/ TableMode FieldSet[MAX_SIZE]; int bFound; /* found the table */ FILE *fp,*tempfp; /定义文件指针/ int tempi,tempi1,tempiNum,iNum,jNum; /*iNum is the number of the Field,and jNum is Record */ char tempc,temps[FILE_NAME_LENGTH],temps1; char recordset[2*MAX_SIZE][FILE_NAME_LENGTH]; char dbf[FILE_NAME_LENGTH]; char datf[FILE_NAME_LENGTH]; char tname[FILE_NAME_LENGTH]; char temptn[FILE_NAME_LENGTH]; / 数据库文件名dbf,表名tname */

char ctemp_edit[15][15],*c; /edit语句的中间变量存放数组/ char ctable_name[10]; int size_edit; /Size/ char key_edit; /Key/ char null_edit; /Null/ char valid_edit; /Valid/ char dbfile[15]; int i=0,j=0,k=0; FILE *fp_edit; int success=0; static int s; /size/ static char ke,n,v; /key,null,valid/

int y=0; char inssql[15][15]; int icd=0; char again; int temp=0; char datafile[15]; int flag=0,sFieldNameFlag=0; int t=0; int r=0; char code[6]; int login=0;

strcpy(dbfile,"edit.tmp") ; strcpy(datafile,"data.tmp");

printf(" —————SQL For DBMS——————— ");

printf(" ————Please LogIN The DBMS————–");

for(i=0;i<5;i++)


讯享网

{ printf(" 

讯享网

LOG>Password:");

讯享网 scanf("%s",code); if(strcmp(code,"admin")==0) { printf(" 

Log in Database Manage System Suceess! ");

 login=1; break; } else { printf(" 

LOG>Wrong Password! ");

讯享网 login=0; } } printf("Please input the datafile name:"); scanf("%s",datf); while(login) { iNum=0; /*iNum置0*/ printf(" 

SQL>");

 scanf("%s",ctemp_edit[0]); switch(ctemp_edit[0][0]) { case 'c': /* 创建新表 */ if (strcmp(ctemp_edit[0],"create")==0) printf(""); else { printf("Wrong SQL! 

");break;}

讯享网 scanf("%s",ctemp_edit[1]); /* table */ scanf("%15s",ctemp_edit[2]); /*表名*/ scanf("%s",ctemp_edit[3]); /* ( */ do{ scanf("%15s",ctemp_edit[4]); /*字段名*/ scanf("%8s",ctemp_edit[5]); /*类型*/ scanf("%d",&size_edit); /*大小*/ scanf("%c",&key_edit); while(key_edit==' ') scanf("%c",&key_edit); /*主键*/ scanf("%c",&null_edit); while(null_edit==' ') scanf("%c",&null_edit); /*空值*/ scanf("%c",&valid_edit); while(valid_edit==' ') scanf("%c",&valid_edit); /*可视化 一般为y*/ strcpy(tempTM.sFieldName,ctemp_edit[4]); /*列名*/ strcpy(tempTM.sType,ctemp_edit[5]); /* 列类型 */ tempTM.iSize=size_edit; /* 大小 */ tempTM.bKey=key_edit; /* 主键 */ tempTM.bNullFlag=null_edit; /* 值是否为空 */ tempTM.bValidFlag=valid_edit; /* 该字段是否有效,这里默认为有效*/ FieldSet[iNum]=tempTM; /*将tempTM放入FieldSet数组内*/ iNum++; /*iNum加1*/ scanf("%c",&again); while(again==' ') scanf("%c",&again); }while(again==','); scanf("%s",ctemp_edit[11]); /* INTO */ scanf("%s",ctemp_edit[12]); /* DataBase_FileName */ if (strcmp(ctemp_edit[1],"table")==0) printf(""); else{ printf(" table ERROR !!! 

");break;}

 if(strcmp(ctemp_edit[3],"(")==0) printf(""); else { printf(" ( ERROR 

"); break;}

讯享网 if(again==')') printf(""); else { printf(" ) ERROR !!! 

"); break;}

 if(strcmp(ctemp_edit[11],"into")==0) printf(""); else { printf(" into error!!! 

"); break;}

讯享网 if((fp=fopen(ctemp_edit[12],"ab+")) == NULL ) { printf(" 

open or create file error!!! " );

 getch(); exit(1); } fwrite("~",sizeof(char),1,fp); fwrite(ctemp_edit[2],sizeof(char),FILE_NAME_LENGTH,fp); fwrite(&iNum,sizeof(int),1,fp); /*此表内所含字段结构的数量*/ fwrite(FieldSet,sizeof(TableMode),iNum,fp); /*表的字段结构*/ fclose(fp); /*关闭文件*/ printf(" 

Table Create Successfully!");

讯享网 break; case 'v': /* 看表 */ if (strcmp(ctemp_edit[0],"view")==0) printf(""); else { printf("Wrong SQL! 

");break;}

 scanf("%s",ctemp_edit[1]); /*读入table*/ scanf("%s",ctemp_edit[2]); /*读入表名*/ scanf("%s",ctemp_edit[3]); /*读入in*/ scanf("%s",dbf); /*读入文件名*/ if (strcmp(ctemp_edit[1],"table")==0) printf(""); else{ printf(" table ERROR !!! 

");break;}

讯享网 if (strcmp(ctemp_edit[3],"in")==0) printf(""); else{ printf(" in ERROR !!! 

");break;}

 if((fp=fopen(dbf,"rb")) == NULL ) { printf(" 

File Not Exist or Bad File! " );

讯享网 break; } if(strcmp(ctemp_edit[2],"*")==0) { printf(" 

Tables in %s are as following:",dbf);

 while(!feof(fp)) { tempi=fread(&tempc,sizeof(char),1,fp); if(!tempi)break; if(tempc!='~') { printf(" 

%s Database Format NOT correct!",dbf);

讯享网 fclose(fp); exit(1); } fread(tname,sizeof(char),FILE_NAME_LENGTH,fp); fread(&iNum,sizeof(int),1,fp); printf(" 

%s",tname);

 fread(FieldSet,sizeof(TableMode),iNum,fp); } break; } else { while(!feof(fp)) { /*输出表所有字段 */ bFound=0; tempi=fread(&tempc,sizeof(char),1,fp); if(!tempi) break; fread(temptn,sizeof(char),FILE_NAME_LENGTH,fp); fread(&iNum,sizeof(int),1,fp); fread(FieldSet,sizeof(TableMode),iNum,fp); if(strcmp(ctemp_edit[2],temptn)==0) { printf(" 

Found! Table Fields are as following:");

讯享网 printf(" 

Field Name Type Size Key Null");

 printf(" 

———— —— —- —- —- ");

讯享网 for(tempi=0;tempi<iNum;tempi++) printf(" 

%-15s|%-8s|%-5d|%-5c|%-5c|",FieldSet[tempi].sFieldName,FieldSet[tempi].sType,FieldSet[tempi].iSize,FieldSet[tempi].bKe


小讯
上一篇 2025-05-03 19:52
下一篇 2025-06-08 10:03

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/199096.html