2数据库的创建与管理,数据操纵

本文介绍了如何创建和管理数据库,包括在MySQL和SQL Server中创建学生、教师和上课表,并进行数据输入、结构修改和数据查询操作。内容涵盖新增字段、修改数据类型、删除列、插入与更新记录、以及各种复杂SQL查询,如添加约束、筛选特定条件的数据等。
摘要由CSDN通过智能技术生成

学生表、教师表以及上课表的建立
一、数据库建立
1.创建teaching数据库
2.利用SQL Server Management Studio创建表student,表结构为
在这里插入图片描述

create table student(studentno nchar(11) not null primary key,sname nchar(8) null,sex nchar(2) null default '男' check(sex='男' or sex='女'),birthday datetime null,classno nchar(6) null,point smallint null,phone nchar(12) null,email nvarchar(20) null)

3.利用Transact-SQL语句在数据库teaching中创建表如下:
(1)课程表

create table 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(courseno))

(2)分数表

create table score(studentno nchar(11) not null ,courseno nchar(6) not null,usually numeric(6,2) null,final numeric(6,2) null,constraint pk_score primary key(studentno,courseno))

(3)教师表

create table teacher(teachno nchar(6) not null primary key,tname nchar(8) null ,major nchar(10) null, prof nchar(10) null,department nchar(12) null)

(4)班级表

create table class(classno nchar(7) not null primary key,classname nchar(12) null,department nchar(12) null,monitor nchar(8) null)

(5)教课表

create table teach_class(teacherno nchar(6) not null ,classno nchar(7) not null,courseno nchar(6) not null,constraint pk_teach_class primary key(teacherno,classno,courseno))

4.为表输入数据。
执行命令:

use teaching  
 insert into student(studentno,sname,sex,birthday,classno,point,phone,email)values('16122210009','许海兵','男','1996/11/05','160501','789','13623456778','qwe@163.com...')
 insert into student(studentno,sname,sex,birthday,classno,point,phone,email)values('16122221324','何影',  '女','1997/12/04','160501','879','13178978999','aaa@sina.com...')
 insert into student(studentno,sname,sex,birthday,classno,point,phone,email)values('16125111109','敬秉承','男','1998/03/01','160801','789','15678945623','jing@sina.com...')
 insert into student(studentno,sname,sex,birthday,classno,point,phone,email)values('16125121107','梁欣',  '女','1996/09/03','160502','777','13145678921','bing@126.com...')
 insert into student(studentno,sname,sex,birthday,classno,point,phone,email)values('16135222201','夏文斐','女','1997/10/06','160502','867','15978945645','tang@163.com...')
 insert into student(studentno,sname,sex,birthday,classno,point
  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值