当前位置:文档之家› 数据库更新操作命令实验

数据库更新操作命令实验


实验内容:
步骤: 将 VC98 和 esqlc 两文件放入 C 盘根目录
启动“MS-DOS”窗口,执行如下命令,使当前盘为 C,当前目录为 esqlc C:
设置系统环境变main 输入程序名 MAIN
回车 连接到数据库 创建教师表 修改,添加
delete
insert into teacher values("T9504", "钱乐", "女",28, "IS") insert into teacher values("T9505", "孙力", "男",26, "MA") insert into teacher values("T9506", "李兰", "女",24, "IS")
commit transaction; if (SQLCODE == 0) {
printf("Success to insert rows to teacher table!%d\n\n",SQLCODE); } else {
printf("ERROR: insert rows %d\n\n",SQLCODE); } return(0); }
it?\n",SQLCODE); printf("Delete the table?(y--yes,n--no):"); scanf("%s",&yn); if (yn[0]=='y' ||yn[0]=='Y'){ EXEC SQL drop table teacher; if (SQLCODE == 0) { printf("Drop table teacher successfully!%d\n\n",SQLCODE); } else { printf("ERROR: drop table teacher %d\n\n",SQLCODE); } } else return -1;
} EXEC SQL CREATE TABLE teacher (
sno char(5) NOT null primary key, sname char(6) null , ssex char(2) null , sage int null , sdept char(2) null) ; if (SQLCODE == 0) { printf("Success to create table teacher!%d\n\n",SQLCODE); } else { printf("ERROR: create table teacher %d\n",SQLCODE); } EXEC SQL begin transaction insert into teacher values("T9501", "李斌", "男",26, "CS") insert into teacher values("T9502", "赵霞", "女",30, "IS") insert into teacher values("T9503", "周淘", "男",27, "CS")
修改:
添加:
代码: int create_teacher_table()
{ char yn[2]; EXEC SQL BEGIN DECLARE SECTION; char tname[21]="xxxxxxxxxxx"; EXEC SQL END DECLARE SECTION; EXEC SQL SELECT name into :tname FROM sysobjects WHERE (xtype = 'U' and name='student'); if (SQLCODE == 0||strcmp(tname,"teacher")==0) { printf("The teacher table already exists,Do you want to
实验六 更新操作命令
实验目的:掌握第三代高级语言(如 C 语言)中嵌入式 SQL 数据库数据操作方法,能
清晰地领略到 SQL 命令在第三代高级语言中操作数据库数据的方式和方法,这种方式和方 法在今后各种数据应用系统开发中将被 广泛的采用。 掌握嵌入了 SQL 语句的 C 语言程序的上机过程包括:编辑、预编译、连接、修改、调试与 运行等内容。
相关主题