数据库课程设计之学生信息管理系统.doc
【精品文档】如有侵权,请联系网站删除,仅供学习与交流数据库课程设计之学生信息管理系统.精品文档.一、引言1课程实验目的课程设计为学生提供了一个既动手又动脑,独立实践的机会,将课本上的理论知识和实际有机的结合起来,锻炼学生的分析解决实际问题的能力。提高学生适应实际,实践编程的能力。课程设计的目的:· 加深对数据库系统、软件工程、程序设计语言的理论知识的理解和应用水平;· 在理论和实验教学基础上进一步巩固已学基本理论及应用知识并加以综合提高;· 学会将知识应用于实际的方法,提高分析和解决问题的能力,增强动手能力;· 为毕业设计和以后工作打下必要基础。2 课程实验题目:设计一个大学教学数据库应用。该系统涉及学生、教师、课程、分组、登记、数据。3 课程设计要求:运用数据库基本理论与应用知识,在微机RDBMS(SQL Server)的环境上建立一个数据库应用系统。要求把现实世界的事物及事物之间的复杂关系抽象为信息世界的实体及实体之间联系的信息模型,再转换为机器世界的数据模型和数据文件,并对数据文件实施检索、更新和控制等操作。1. 用E-R图设计指定题目的信息模型;2. 设计相应的关系模型,确定数据库结构;3. 分析关系模式各属于第几范式,阐明理由;4. 设计应用系统的系统结构图,确定系统功能;5. 使用对象许可和命令许可、角色控制设计安全性控制检查程序;6. 通过设计关系的主码约束、外码约束和使用CHECK、RULE实现完整性控制;7. 为每一参照关系设计插入、删除、修改触发器;8. 实现应用程序设计、编程、优化功能;9. 对系统的各个应用程序进行集成和调试,进一步优化系统功能、改善系统用户界面完成实验内容所指定的各项要求;10. 分析遇到的问题,总结并写出课程设计报告;11. 自我评价二、 用E-R图设计选定题目的信息模型 学生实体的E-R图cityzipaddressStudent_namestatestudentsexSTUDENTS 教师实体E-R图phoneTeacher_namesalaryteacherTEACHERS 课程实体E-R图departmentnurc_creditsCourse_namecourseCOURSES 分组实体E-R图teachersectionnum_studentscourseSECTIONS 教师任课实体E-R图sectiongradestudentcourseENROLLS 三、设计相应的关系模型,确定数据库结构* STUDENTS(student,student_name,address,zip,city,state,sex)* TEACHERS(teacher,teacher_name,phone,salary)* COURSES(course,course_name,department,nurc_credits)* SECTION(section,teacher,course,num_students)* ENROLLS(course,section,student,grade)· 分析关系模式各属于第几范式,阐明理由;STUDENTS 属于BCNF,因为其中的每个决定因素都包含了码TEACHERS 属于BCNF,因为其中的每个决定因素都包含了码COURSES 属于BCNF,因为其中的每个决定因素都包含了码ENROLLS 属于BCNF,因为其中的每个决定因素都包含了码SECTION 属于BCNF, 因为其中的每个决定因素都包含了码 · 设计关系的主码约束、外码约束和使用CHECK实现完整性控制; STUDENTS信息基本表 create table STUDENTS( student char(8) primary key, student_name char(20), address char(20), zip char(10), city char(20), state char(8), sex char(2); TEACHERS基本表 create table TEACHERS( teacher char(8) primary key, teacher_name char(10), phone char(10), salary char(8); COURSES基本表 create table COURSES( course char(8) primary key, course_name char(20), department char(20), nurc_credits char(4); SECTION表 create table SECTION( section char(4), teacher char(8) primary key, course char(8), num_students char(4), foreign key (course) references COURSES(course); ENROLLS表 create table ENROLLS( course char(8), section char(4), student char(8), grade SMALLINT, primary key(course,section,student), foreign key (course) references COURSES(course), foreign key (student) references STUDENTS(student);· 为参照关系设计插入、删除、修改触发器;· 实现应用程序设计、编程、优化功能;· 对系统的各个应用程序进行集成和调试,进一步优化系统功能、改善系统用户界面完成实验内容所指定的各项要求;四、源程序代码清单using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace WindowsFormsApplication2 public partial class Form1 : Form public Form1() InitializeComponent(); private void 学生ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from STUDENTS", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /学生基本信息 private void 教师ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from TEACHERS", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "TEACHERS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /教师基本信息 private void 课程ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from COURSES", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "COURSES"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /课程基本信息 private void 分组ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from SECTION", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "SECTION"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /分组基本信息 private void 登记ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from ENROLLS", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "ENROLLS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /登记基本信息 private void 查询1 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select* from COURSES where department IN('Math','English')", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "COURSES"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索系名为“Math”和“English”的课程表信息 private void 查询2 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select teacher_name,phone from TEACHERS order by teacher_name", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "TEACHERS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /按字母顺序列出教师姓名和电话号码 private void 查询3 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select teacher_name,phone from TEACHERS where phone not like '257%'", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "TEACHERS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索电话号码不是以“257”打头的教师姓名和电话号码 private void 查询4 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select course_name,department,nurc_credits from COURSES where department='Math' and nurc_credits>'3'", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "COURSES"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索数学系所有成绩大于3的课程名、系名、学分 private void 查询5 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select student_name,student from STUDENTS where not exists (select* from ENROLLS where STUDENTS.student=ENROLLS.student)", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS,ENROLLS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索没有选修任何课的学生姓名、学号 private void 查询6 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select student from STUDENTS where not exists (select* from ENROLLS,COURSES where STUDENTS.student=ENROLLS.student and COURSES.course=ENROLLS.course and course_name='Calculus Iv')", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS,ENROLLS,COURSES"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索没有选修课程“Calculus Iv”的学生学号 private void 查询7 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select distinct student from ENROLLS A where not exists (select* from TEACHERS where teacher_name='Dr.Lowe' and not exists (select * from ENROLLS B where B.course=A.course)", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "TEACHERS,ENROLLS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索至少选修教师“Dr. Lowe”所开全部课程的学生学号 private void 查询8 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select COURSES.course,count(num_students),COURSES.course_name from SECTION,COURSES where COURSES.course=SECTION.course group by COURSES.course_name,COURSES.course ", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "COURSES,SECTION"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索每门课学生登记的人数、相应的课程名、课程号、分组号 private void 查询9 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select student_name from STUDENTS where student in(select student from ENROLLS group by student having count(*)>2 )", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS,ENROLLS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索选修两门以上课程的学生姓名 private void 查询10 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select distinct course,student_name from STUDENTS,ENROLLS where ENROLLS.student=STUDENTS.student and sex='M'", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS,ENROLLS"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索只有男生选修的课程和学生名 private void 查询11 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select STUDENTS.student_name,COURSES.course_name,TEACHERS.teacher_name,ENROLLS.grade from COURSES,STUDENTS,TEACHERS,ENROLLS,SECTION where STUDENTS.student=ENROLLS.student and ENROLLS.course=COURSES.course and SECTION.teacher=TEACHERS.teacher and SECTION.course=COURSES.course", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "STUDENTS,ENROLLS,TEACHERS,COURSES,SECTION"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); /检索所有学生选修的课程名、学生名、授课教师名、该生成绩 private void 查询12 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select avg(grade) from COURSES,ENROLLS,TEACHERS,SECTION where COURSES.course=ENROLLS.course and TEACHERS.teacher=SECTION.teacher and course_name='english composition' and teacher_name like '%Engle'", conn); DataSet ds1 = new DataSet(); sdr1.Fill(ds1, "ENROLLS,TEACHERS,COURSES,SECTION"); dataGridView1.DataSource = ds1.Tables0; conn.Close(); / 统计教师“Engle”教的英语课的学生平均分 private void 查询13 ToolStripMenuItem_Click(object sender, EventArgs e) string connectionStr = "Data Source=qinjia-PC;Initial Catalog=sjk;Integrated Security=True" SqlConnection conn = new SqlConnection(connectionStr); conn.Open(); SqlDataAdapter sdr1 = new SqlDataAdapter("select course_name,count(num_students) from COURSES,SECTION where COURSES.course=SECT