当前位置:网站首页 > SQL数据库编程 > 正文

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

/* 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

到此这篇增删改查sql语句问题与解决(增、删、改、查 对应的sql语法)的文章就介绍到这了,更多相关 内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • mysql主键和外键的建立(mysql主键,外键)2025-01-26 23:18:08
  • mysql主键重复报错1062(mysql主键重复报错)2025-01-26 23:18:08
  • mysql主键和索引(mysql主键索引为什么快)2025-01-26 23:18:08
  • mysql主键查询慢(mysql查询主键的语句)2025-01-26 23:18:08
  • sql文件是什么(sql文件有什么用)2025-01-26 23:18:08
  • mysql查询锁表怎么办(mysql查询时会锁表吗)2025-01-26 23:18:08
  • sqlldr怎么使用(sqlldr教程)2025-01-26 23:18:08
  • 增删改查sql语句(增删改查sql语句语法)2025-01-26 23:18:08
  • 锁表(mysql查询锁表)2025-01-26 23:18:08
  • sql文件导入sql数据库(sql文件怎么导入数据库mysql)2025-01-26 23:18:08
  • 全屏图片