create index SC_FK on SC (学号 ASC) Go
create index SC2_FK on SC (课程号 ASC) go
建立课程号索引
create index TC_FK on TC ( 课程号 ASC )
go
下图显示了学生,课程和成绩三个关系的物理设计其中课程号与学号号分别为关系的主码。
五 数据库的实施与维护
5.1 数据库的实施:
此阶段主要任务包括创建数据库,加载初始数据,数据库试运行,数据库的安全性和完整性控制数据库的备份与恢复,数据库性能的监督分析和改仅,数据库的重组和重构等。首先在数据库中建立一个学生成绩管理系统数据库,然后新建一个数据源。主要代码如下:
#include \#include \#include \#ifdef _DEBUG
#define new DEBUG_NEW #undef THIS_FILE
static char THIS_FILE[] = __FILE__; // CCourse
IMPLEMENT_DYNAMIC(CCourse, CRecordset) CCourse::CCourse(CDatabase* pdb) { {
: CRecordset(pdb)
//{{AFX_FIELD_INIT(CCourse) //}}AFX_FIELD_INIT m_nDefaultType = snapshot; return _T(\
6
CString CCourse::GetDefaultConnect()
}
CString CCourse::GetDefaultSQL() { { }
// CCourse diagnostics
void CCourse::AssertValid() const { {
CRecordset::AssertValid();} CRecordset::Dump(dc);}
void CCourse::Dump(CDumpContext& dc) const // MainFrm.h : interface of the CMainFrame class class CMainFrame : public CFrameWnd {protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame) //{{AFX_FIELD_MAP(CCourse)
pFX->SetFieldType(CFieldExchange::outputColumn); //}}AFX_FIELD_MAP return _T(\
void CCourse::DoFieldExchange(CFieldExchange* pFX)
// Attributes public: // Operations public: // Overrides
// ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL
// Implementation public:
virtual ~CMainFrame(); //CStatusBar m_wndStatusBar; //CToolBar m_wndToolBar; protected: // control bar embedded members
// Generated message map functions protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnPassword(); afx_msg void OnUser(); afx_msg void OnStudent(); afx_msg void OnTeach(); afx_msg void OnTeacher(); afx_msg void OnScore();
7
};
afx_msg void OnQueryTeach(); afx_msg void OnQueryScore(); afx_msg void OnCourse(); //}}AFX_MSG
DECLARE_MESSAGE_MAP()
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. // CScoreAddDlg dialog
CScoreAddDlg::CScoreAddDlg(CWnd* pParent /*=NULL*/) }
void CScoreAddDlg::DoDataExchange(CDataExchange* pDX) { }
BEGIN_MESSAGE_MAP(CScoreAddDlg, CDialog)
//{{AFX_MSG_MAP(CScoreAddDlg) //}}AFX_MSG_MAP
CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CScoreAddDlg)
DDX_Control(pDX, IDC_SCORE_STUDENT, m_cStudent); DDX_Control(pDX, IDC_SCORE_SCORE, m_cScore); DDX_Control(pDX, IDC_SCORE_COURSE, m_cCourse); //}}AFX_DATA_MAP
: CDialog(CScoreAddDlg::IDD, pParent) //}}AFX_DATA_INIT
{/{{AFX_DATA_INIT(CScoreAddDlg)
END_MESSAGE_MAP() void CScoreAddDlg::OnOK() {
CString student,course,score,student_no,course_no; m_cStudent.GetWindowText(student); m_cCourse.GetWindowText(course); else//成绩不为空 {
CString strSQL; //查出该学生的学号
strSQL.Format(\CRecordset m_recordSet=&m_database;
m_recordSet.Open(CRecordset::forwardOnly,strSQL); m_recordSet.Close(); //查出该课程的课程号
m_cScore.GetWindowText(score);
m_recordSet.GetFieldValue(\
strSQL.Format(\
8
{ }
m_recordSet.Open(CRecordset::forwardOnly,strSQL); m_recordSet.Close();
m_recordSet.GetFieldValue(\BOOL CScoreAddDlg::OnInitDialog()
CDialog::OnInitDialog(); CRecordset m_recordSet; if(!m_database.IsOpen()) { }
CString strSQL;
strSQL.Format(\for(int i=0;i m_recordSet.Close(); strSQL.Format(\for(int j=0;j m_recordSet.Close(); { } return true; this->SetWindowText(\成绩窗口\CString temp; m_recordSet.GetFieldValue(\m_cStudent.AddString(temp); CString temp; m_recordSet.GetFieldValue(\m_cCourse.AddString(temp); m_database.Open(_T(\ m_recordSet.m_pDatabase=&m_database; m_recordSet.Open(CRecordset::forwardOnly,strSQL); m_recordSet.MoveNext(); m_cCourse.SetCurSel(1); m_recordSet.Open(CRecordset::forwardOnly,strSQL); m_recordSet.MoveNext(); m_cStudent.SetCurSel(1); void CScoreAddDlg::OnCancel() { } // TODO: Add extra cleanup here CDialog::OnCancel(); 9 5.2部分操作截图: 下图显示了学生登陆系统进行查询时界面: 成绩查询功能: 下图显示了进行课程查询时界面: 5.3数据库的维护 当试运行数据库合格后,数据库开发设计的工作就基本完成了,接下来就是正式运行中的调试,应为该系统比较简单,数据量小,数据库中几乎不会发生什么大的变化,但是还是需要做好数据的备份,在sqlserver中我们可以利用备份数据库的功能对已经设计好的数据做备份,如果数据库受到破坏或系统故障,我们便可轻松的利用备份文件恢复数据库的数据。当然也可以利用其他各种方法进行数据维护。 六 总结 进一步深入理解数据库设计的整个过程,该学生选课系统的需求分析、数据库概念结构设计有关内容等。掌握使用前台程序设计技术VC和SQL Server结合设计 C /S结构的管理信息系统。综合练习了SQL Server的使用和数据库得管理技术。综合熟悉并练习了SQL语言在编程中的使用。 综合训练编程能力。认识系统,取得系统需求分析,更重要得是在编程方面提高了实现目标代码得能力及调试代码得能力 参考文献 (1)《Visual C++数据库开发经典实例精解》作者:夏邦国 刘凡馨 出版社:机械工业出版社 (2)《SQL SERVER 200管理,开发及应用实例》作者:陈世洪 出版社:人民邮电出版社 (3)《Visual C++程序设计教程》 作者:周鸣扬 于秋生 出版社:机械工业出版社 (4)《数据库原理与应用》 作者:姜代红 出版社:机械工业出版社 (5) S.Sanyal and P.Chattopadhyay.Effect of exponentially distributed deep levels on the current and capacitance of a MIS diode[J].Solid-state electronics,2001,45(2):315-324.