文档详情

实验3数据库数据的定义与简单查询操作1.doc

发布:2016-11-03约6.24千字共6页下载文档
文本预览下载声明
实验三:数据库数据的定义与简单查询操作 一、实验目的 熟练掌握建立数据库和表,向数据库输入数据、修改数据和删除数据的操作及简单的查询操作。 二、实验内容和要求 建立数据库并设计各表,输入多条实际数据,并实现数据的增、删、改操作。查询数据库中的表和表中各数据的定义。设计各种单表查询SQL语句。 三、实验步骤 创建学生管理数据库,数据库名为test,包含学生的基本信息,课程信息和选课信息。数据库xsgl包含下列3个表: (l) student:学生基本信息。 (2)course:课程信息表。 (3)sc:学生选课表。 各表的结构分别如实验二的表1-1、表1-2和表1-3所示。 1、数据库的建立: 用可视化界面建立: 在KingbaseES中用企业管理器-新建数据库; 命令方式建立: 在KingbaseES中,在查询分析器中使用SQL语句: 创建“test”数据库: Create database test with Encoding=’GBK’; 创建”xsgl”模式: Create schema xsgl; 2. 表的建立: 用可视化界面建立: 在KingbaseES中用企业管理器—数据库—test—表—右键—新建表; 命令方式建立: 在KingbaseES中查询分析器的编辑窗口中用下列SQL语句: 在“xsgl”模式中建立表格“student”、“course”、“sc”: SET Search_path To xsgl, public; Create table student( sno CHAR(10) not null, sname CHAR(10) not null, ssex CHAR(2) not null, sage int not null, sdept CHAR(4) not null, primary key (sno)); Create table course( cno CHAR(3), cname CHAR(30), credit INT, pcno CHAR(3) NULL, primary key (cno)); ……. 或者: Create table xsgl.student( sno CHAR(10) not null, sname CHAR(10) not null, ssex CHAR(2) not null, sage int not null, sdept CHAR(4) not null, primary key (sno)); Create table xsgl.course( cno CHAR(3), cname CHAR(30), credit INT, pcno CHAR(3) NULL, primary key (cno)); Create table xsgl.sc( sno CHAR(10), cno CHAR(3), grade INT NULL, primary key (sno, cno)); 3. 表数据的添加: (1). 用可视化方法: I: 在KingbaseES中用企业管理器—数据库—test—表-表名—右键-打开表-返回所有行; 输入下列数据: sno sname ssex sage sdept 95001 李勇 男 20 CS 95002 刘晨 女 19 IS 95003 王敏 女 18 MA 95004 张立 男 19 IS 95005 刘云 女 18 CS cno cname credit pcno 1 数据库 4 5 2 数学 6 3 信息系统 3 1 4 操作系统 4 6 5 数据结构 4 7 6 数据处理 3 7 PASCAL语言 4 6 sno cno grade 95001 1 92 95001 2 85 95001 3 88 95002 2 90 95002 3 80 95003 2 85 95004 1 58 95004 2 85 (2). 在KingbaseES查询分析器的编辑窗口中使用下列SQL 语句插入数据: insert into xsgl.student(sno, sname, ssex, sage, sdept) values(95001, 李勇, 男, 20, CS); insert into xsgl.student(sno, sname, ssex, sage, sdept) values(95002, 刘晨, 女, 19, IS); insert into xsgl.student(sno, sname, ssex, sage, sdept) values(95003, 王敏, 女, 1
显示全部
相似文档