数据库学习笔记(四)

//生成数据库teaching脚本

USE master

GO

IF EXISTS(

SELECT name

FROM sys.databases

WHERE name = N‘teaching‘

)

DROP DATABASE teaching

CREATE DATABASE teaching

ON  PRIMARY

( NAME = N‘teaching‘, FILENAME = N‘E:\DATA\teaching.mdf‘ , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

LOG ON

( NAME = N‘teaching_log‘, FILENAME = N‘E:\DATA\teaching_log.ldf‘ , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

GO

USE teaching

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘student‘

)

DROP TABLE student

CREATE TABLE student(

studentno nchar(10) NOT NULL,

sname nchar(8) NOT NULL,

sex nchar(1) NOT NULL,

birthday datetime NOT NULL,

classno nchar(6) NOT NULL,

point smallint NOT NULL,

phone nchar(12) NOT NULL,

Email nchar(20) NOT NULL,

CONSTRAINT CK_sex CHECK (sex=‘男‘ OR sex=‘女‘),

CONSTRAINT PK_student PRIMARY KEY CLUSTERED (studentno  ASC)

)

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘course‘

)

DROP TABLE dbo.course

CREATE TABLE dbo.course(

courseno nchar(6) NOT NULL,

cname nchar(20) NULL,

type nchar(8) NULL,

period tinyint NULL,

credit numeric(4, 1) NULL,

CONSTRAINT PK_course PRIMARY KEY CLUSTERED (Courseno  ASC)

)

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘teacher‘

)

DROP TABLE dbo.teacher

CREATE TABLE dbo.teacher(

teacherno nchar(6) NOT NULL,

tname nchar(8) NULL,

major nchar(10) NULL,

prof nchar(10) NOT NULL,

department nchar(12)  NULL,

CONSTRAINT PK_teacher PRIMARY KEY CLUSTERED (teacherno ASC)

)

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘class‘

)

DROP TABLE dbo.class

CREATE TABLE dbo.class(

classno nchar(6)  NOT NULL,

classname nchar(12) NULL,

department nchar(12) NULL,

monitor nchar(8) NULL,

CONSTRAINT PK_class PRIMARY KEY CLUSTERED (classno ASC)

)

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘score‘

)

DROP TABLE dbo.score

CREATE TABLE dbo.score(

studentno nchar(10)  NOT NULL,

courseno  nchar(6)  NOT NULL,

usually numeric(6, 2) DEFAULT 0,

final numeric(6, 2) DEFAULT 0,

score as usually*30/100+final*70/100,

CONSTRAINT PK_score PRIMARY KEY CLUSTERED (studentno ASC,courseno ASC)

)

GO

IF EXISTS (

SELECT * FROM sys.objects

WHERE name = N‘teach_class‘

)

DROP TABLE dbo.teach_class

CREATE TABLE dbo.teach_class(

teacherno nchar(6) NOT NULL,

classno nchar(6) NOT NULL,

courseno  nchar(6) NOT NULL,

CONSTRAINT PK_teach_class PRIMARY KEY CLUSTERED (teacherno ASC,classno ASC,courseno ASC)

)

GO

ALTER TABLE score

ADD CONSTRAINT FK_score_student FOREIGN KEY (studentno) REFERENCES student (studentno) ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT FK_score_course  FOREIGN KEY (courseno)  REFERENCES course (courseno) ON UPDATE CASCADE ON DELETE CASCADE

GO

ALTER TABLE teach_class

ADD CONSTRAINT FK_teach_class_teacher FOREIGN KEY (teacherno) REFERENCES teacher (teacherno) ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT FK_teach_class_class   FOREIGN KEY (classno)   REFERENCES class (classno) ON UPDATE CASCADE ON DELETE CASCADE,

CONSTRAINT FK_teach_class_course  FOREIGN KEY (courseno)  REFERENCES course (courseno) ON UPDATE CASCADE ON DELETE CASCADE

GO

CREATE RULE score_rule AS

@score BETWEEN 0 AND 100

GO

EXEC sp_bindrule ‘score_rule‘,‘score.usually‘

EXEC sp_bindrule ‘score_rule‘,‘score.final‘

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0822111208‘,‘韩吟秋‘,‘男‘,‘1989-12-18‘,‘080601‘,666,‘15878945612‘,‘[email protected]‘  )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0823210007‘,‘宿致远‘,‘男‘,‘1988-12-7‘, ‘080501‘,658,‘12545678998‘,‘[email protected]‘ )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0824113307‘,‘崔岩坚‘,‘男‘,‘1988-4-8‘,  ‘080601‘,787,‘15556845645‘,‘[email protected]‘  )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0922210009‘,‘许海冰‘,‘男‘,‘1989-9-8‘,  ‘080501‘,789,‘13623456778‘,‘[email protected]‘  )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0922221324‘,‘何影‘,  ‘女‘,‘1990-10-7‘, ‘080501‘,879,‘13178978999‘,‘[email protected]‘ )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0925111109‘,‘敬秉辰‘,‘男‘,‘1991-1-2‘,  ‘080801‘,789,‘15678945623‘,‘[email protected]‘)

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0925121107‘,‘梁欣‘,  ‘女‘,‘1989-7-7‘,  ‘080502‘,777,‘13145678921‘,‘[email protected]‘ )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0935222201‘,‘夏文婓‘,‘女‘,‘1990-8-9‘,  ‘080502‘,867,‘15978945645‘,‘[email protected]‘ )

insert into student (studentno,sname,sex,birthday,classno,point,phone,Email)values(‘0937221508‘,‘平靖‘,  ‘女‘,‘1989-12-17‘,‘080802‘,789,‘12367823453‘,‘[email protected]‘ )

insert into teacher (teacherno,tname,major,prof,department) values (‘t05001‘,‘韩晋升‘,‘软件工程‘  ,‘教授‘  ,‘计算机学院‘)

insert into teacher (teacherno,tname,major,prof,department) values (‘t05003‘,‘刘元朝‘,‘网络技术‘  ,‘教授‘  ,‘计算机学院‘)

insert into teacher (teacherno,tname,major,prof,department) values (‘t05011‘,‘海封‘  ,‘计算机设计‘,‘副教授‘,‘计算机学院‘)

insert into teacher (teacherno,tname,major,prof,department) values (‘t05017‘,‘卢明欣‘,‘软件测试‘  ,‘讲师‘  ,‘计算机学院‘)

insert into teacher (teacherno,tname,major,prof,department) values (‘t06011‘,‘胡海悦‘,‘机械制造‘  ,‘教授‘  ,‘机械学院‘  )

insert into teacher (teacherno,tname,major,prof,department) values (‘t06023‘,‘姚思远‘,‘铸造工艺‘  ,‘副教授‘,‘机械学院‘  )

insert into teacher (teacherno,tname,major,prof,department) values (‘t07019‘,‘马爱芬‘,‘经济管理‘  ,‘讲师‘  ,‘管理学院‘  )

insert into teacher (teacherno,tname,major,prof,department) values (‘t08017‘,‘田有余‘,‘金融管理‘  ,‘副教授‘,‘管理学院‘  )

insert into course (courseno,cname,type,period,credit) values (‘c05103‘,‘电子技术‘,‘必修‘,64,4.0)

insert into course (courseno,cname,type,period,credit) values (‘c05109‘,‘C语言‘   ,‘必修‘,72,4.5)

insert into course (courseno,cname,type,period,credit) values (‘c05127‘,‘数据结构‘,‘必修‘,64,4.0)

insert into course (courseno,cname,type,period,credit) values (‘c05138‘,‘软件工程‘,‘选修‘,48,3.0)

insert into course (courseno,cname,type,period,credit) values (‘c06108‘,‘机械制图‘,‘必修‘,60,3.5)

insert into course (courseno,cname,type,period,credit) values (‘c06127‘,‘机械设计‘,‘必修‘,64,4.0)

insert into course (courseno,cname,type,period,credit) values (‘c06172‘,‘铸造工艺‘,‘选修‘,42,2.5)

insert into course (courseno,cname,type,period,credit) values (‘c08106‘,‘经济法‘  ,‘必修‘,48,3.0)

insert into course (courseno,cname,type,period,credit) values (‘c08123‘,‘金融学‘  ,‘必修‘,40,2.5)

insert into course (courseno,cname,type,period,credit) values (‘c08171‘,‘会计软件‘,‘选修‘,32,2.0)

insert into class (classno,classname,department,monitor) values (‘080501‘,‘计08本1班‘,‘计算机学院‘,‘韩吟秋‘)

insert into class (classno,classname,department,monitor) values (‘080502‘,‘计08本2班‘,‘计算机学院‘,‘宿致远‘)

insert into class (classno,classname,department,monitor) values (‘080601‘,‘机08本1班‘,‘机械学院‘  ,‘崔岩坚‘)

insert into class (classno,classname,department,monitor) values (‘080602‘,‘机08本2班‘,‘机械学院‘  ,‘韩吟秋‘)

insert into class (classno,classname,department,monitor) values (‘080801‘,‘管08本1班‘,‘管理学院‘  ,‘许海冰‘)

insert into class (classno,classname,department,monitor) values (‘080802‘,‘管08本2班‘,‘管理学院‘  ,‘何影‘)

insert into score(studentno,courseno,usually,final) values (‘0822111208‘,‘c05109‘,85.00,91.00)

insert into score(studentno,courseno,usually,final) values (‘0822111208‘,‘c06108‘,89.00,95.00)

insert into score(studentno,courseno,usually,final) values (‘0822111208‘,‘c06127‘,78.00,67.00)

insert into score(studentno,courseno,usually,final) values (‘0823210007‘,‘c05103‘,82.00,69.00)

insert into score(studentno,courseno,usually,final) values (‘0823210007‘,‘c05109‘,87.00,86.00)

insert into score(studentno,courseno,usually,final) values (‘0824113307‘,‘c05103‘,85.00,77.00)

insert into score(studentno,courseno,usually,final) values (‘0824113307‘,‘c05109‘,88.00,79.00)

insert into score(studentno,courseno,usually,final) values (‘0824113307‘,‘c06108‘,66.00,82.00)

insert into score(studentno,courseno,usually,final) values (‘0922210009‘,‘c05103‘,87.00,82.00)

insert into score(studentno,courseno,usually,final) values (‘0922210009‘,‘c05109‘,77.00,91.00)

insert into score(studentno,courseno,usually,final) values (‘0922221324‘,‘c05103‘,88.00,62.00)

insert into score(studentno,courseno,usually,final) values (‘0922221324‘,‘c05109‘,91.00,77.00)

insert into score(studentno,courseno,usually,final) values (‘0925111109‘,‘c08106‘,79.00,99.00)

insert into score(studentno,courseno,usually,final) values (‘0925111109‘,‘c08123‘,85.00,92.00)

insert into score(studentno,courseno,usually,final) values (‘0925111109‘,‘c08171‘,77.00,92.00)

insert into score(studentno,courseno,usually,final) values (‘0925121107‘,‘c05103‘,74.00,91.00)

insert into score(studentno,courseno,usually,final) values (‘0925121107‘,‘c05109‘,89.00,62.00)

insert into score(studentno,courseno,usually,final) values (‘0935222201‘,‘c05109‘,99.00,92.00)

insert into score(studentno,courseno,usually,final) values (‘0935222201‘,‘c08171‘,95.00,82.00)

insert into score(studentno,courseno,usually,final) values (‘0937221508‘,‘c08106‘,78.00,95.00)

insert into score(studentno,courseno,usually,final) values (‘0937221508‘,‘c08123‘,78.00,89.00)

insert into score(studentno,courseno,usually,final) values (‘0937221508‘,‘c08171‘,88.00,98.00)

insert into teach_class(teacherno,classno,courseno) values (‘t05001‘,‘080501‘,‘c05103‘)

insert into teach_class(teacherno,classno,courseno) values (‘t05001‘,‘080501‘,‘c05109‘)

insert into teach_class(teacherno,classno,courseno) values (‘t05001‘,‘080501‘,‘c05127‘)

insert into teach_class(teacherno,classno,courseno) values (‘t05017‘,‘080501‘,‘c05138‘)

insert into teach_class(teacherno,classno,courseno) values (‘t05017‘,‘080501‘,‘c06108‘)

insert into teach_class(teacherno,classno,courseno) values (‘t05017‘,‘080501‘,‘c06127‘)

insert into teach_class(teacherno,classno,courseno) values (‘t08017‘,‘080501‘,‘c08171‘)

insert into teach_class(teacherno,classno,courseno) values (‘t08017‘,‘080501‘,‘c06172‘)

insert into teach_class(teacherno,classno,courseno) values (‘t08017‘,‘080501‘,‘c08106‘)

insert into teach_class(teacherno,classno,courseno) values (‘t07019‘,‘080501‘,‘c08123‘)

insert into teach_class(teacherno,classno,courseno) values (‘t07019‘,‘080501‘,‘c08171‘)

GO

时间: 2024-11-05 04:47:15

数据库学习笔记(四)的相关文章

[转]mnesia数据库学习笔记

mnesia数据库学习笔记一 mnesia数据库学习笔记二 mnesia数据库学习笔记三 mnesia数据库学习笔记四

Linux学习笔记四:Linux的文件搜索命令

1.文件搜索命令  which 语法:which [命令名称] 范例:$which ls  列出ls命令所在目录 [[email protected] ~]$ which ls alias ls='ls --color=auto' /bin/ls 另外一个命令:whereis [名称名称],也可以列出命令所在目录. [[email protected] ~]$ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/ma

Caliburn.Micro学习笔记(四)----IHandle<T>实现多语言功能

Caliburn.Micro学习笔记(四)----IHandle<T>实现多语言功能 说一下IHandle<T>实现多语言功能 因为Caliburn.Micro是基于MvvM的UI与codebehind分离, binding可以是双向的所以我们想动态的实现多语言切换很是方便今天我做一个小demo给大家提供一个思路 先看一下效果 点击英文  变成英文状态点chinese就会变成中文                          源码的下载地址在文章的最下边 多语言用的是资源文件建

代码管理工具 --- git的学习笔记四《重新整理git(1)》

1.创建版本库 mkdir  创建目录 cd  地址,到该地址下 pwd 显示当前目录 1.创建目录 $ mkdir startGit $ cd startGit $ pwd 显示当前目录 或者cd到桌面,然后再创建目录 2.初始化版本库 $ git init 初始化仓库 提示信息:Initialized empty Git repository in /Users/xingzai/Desktop/startGit/.git/ 建立一个空的git仓库在/Users/xingzai/Desktop

小猪的数据结构学习笔记(四)

小猪的数据结构学习笔记(四) 线性表之静态链表 --转载请注明出处:coder-pig 本章引言: 在二,三中中我们分别学习了顺序表中的线性表与单链表,线性表有点类似于 我们前面所学的数组,而单链表使用的最多的是指针,这里问个简单的问题, 如果是在以前没有指针的话,前辈先人们怎么实现单链表呢?大家思考下! 没有指针,那么用什么来代替呢?前辈先人们非常机智,想出了使用下标+游标的方式 来实现单链表的效果!也就是今天要讲的--静态链表! 当然你也可以直接跳过本章,因为有了单链表就没有必要用静态链表了

Swift学习笔记四:数组和字典

最近一个月都在专心做unity3d的斗地主游戏,从早到晚,最后总算是搞出来了,其中的心酸只有自己知道.最近才有功夫闲下来,还是学习学习之前的老本行--asp.net,现在用.net做项目流行MVC,而不是之前的三层,既然技术在更新,只能不断学习,以适应新的技术潮流! 创建MVC工程 1.打开Visual studio2012,新建MVC4工程 2.选择工程属性,创建MVC工程 3.生成工程的目录 App_Start:启动文件的配置信息,包括很重要的RouteConfig路由注册信息 Conten

数据库学习笔记(一)

1.在ORACLE里默认只有三个系统用户,ORACLE是通过用户登入.  SYS用户:超级管理员,权限最高,它的角色是DBA.默认密码是change_on_install.具有创建数据库的权限   SYSTEM用户:系统管理员,权限很高,它的角色是DBA operator,默认密码manager.不具有创建数据库的权限!  普通用户(normal),如系统安装时的scott用户,默认密码是tiger.普通用户的权限是SYS用户或SYSTEM用户给的. 在SQL SERVER里是通过WINDOWS

MySQL数据库学习笔记(十)----JDBC事务处理、封装JDBC工具类

首先需要回顾一下上一篇文章中的内容:MySQL数据库学习笔记(九)----JDBC的PreparedStatement接口重构增删改查 一.JDBC事务处理: 我们已经知道,事务的概念即:所有的操作要么同时成功,要么同时失败.在MySQL中提供了Commit.Rollback命令进行事务的提交与回滚.实际上在JDBC中也存在事务处理,如果要想进行事务处理的话,则必须按照以下的步骤完成. JDBC中事务处理的步骤: 1.要取消掉JDBC的自动提交:void setAutoCommit(boolea

NLTK学习笔记(四):自然语言处理的一些算法研究

自然语言处理中算法设计有两大部分:分而治之 和 转化 思想.一个是将大问题简化为小问题,另一个是将问题抽象化,向向已知转化.前者的例子:归并排序:后者的例子:判断相邻元素是否相同(与排序). 这次总结的自然语言中常用的一些基本算法,算是入个门了. 递归 使用递归速度上会受影响,但是便于理解算法深层嵌套对象.而一些函数式编程语言会将尾递归优化为迭代. 如果要计算n个词有多少种组合方式?按照阶乘定义:n! = n*(n-1)*...*1 def func(wordlist): length = le

Android学习笔记四:添加Source

问题描述 Source not foundThe JAR file D:\.....\sdk\platforms\android-20\android.jar has no source attachment. 问题原因及解决办法 1. 使用SDK Manager下载最新版本的Sources for Android SDK 一般文件下载目录默认在SDK下的sources文件中即 \adt-bundle-windows-x86_64-20130522\sdk\sources\android-20