数据库表格的创建

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

课后习题名称:学生选课管理系统(stuCourse)

create database stuCourse;

1、创建名为stuCourse的数据库。

create database stuCourse;

2、向stuCourse数据库里创建三张表,表名分别为:

stu(学生信息表)、sc(选课表)、teacher(教师信息表)

学生表(stu)结构

use stuCourse

create table stu

(

sno char(6) not null primary key,

sname char(10) not null,

sex char(2) null,

age int null,

dept char(20) null

)

选课表(sc)结构

create table sc

(

sno char(6) not null primary key ,

score float not null,

courseid char(8) not null

)

教师信息表(teacher)结构

create table teacher

(

tno char(8) not null primary key,

tname char(8) not null,

prof char(10) ,

salary float ,

dept varchar(20)

)

3、向表stu中增加新的一列家庭住址address。

4、把表stu中的年龄age的数据类型改为tinyint。

5、利用insert语句向以上三个表插入数据。数据如下:表stu中的数据:

插入stu表中

insert into stu

values ( '1001','宋江', '男', 25, '计算机系' );

insert into stu

values ( '3002','张明', '男', 23, '生物系' );

insert into stu

values ( '1003','李小鹏', '男', 26, '计算机系' );

insert into stu

values ( '1004','郑冬', '女', 25, '计算机系' );

insert into stu

values ( '4005','李小红', '女', 27, '工商管理' );

insert into stu

values ( '5006','赵紫月', '女', 24, '外语系' )

表sc中的数据:

插入sc表中

insert into sc

values ('1001', 67, 'C1'),('3002', 78, 'C3'),('1003', 89, 'C1'),('1004', 56, 'C2'),('4005', 87, 'C4'),('5006', 0, 'C1')

表teacher中的数据:

插入teacher表中

insert into teacher

values ('3102', '李明', '初级', '2500', '计算机系'); insert into teacher

values ('4105', '张小红', '中级', '3500', '工商管理'); insert into teacher

values ('5102', '宋力月', '高级', '3500', '物理系'); insert into teacher

values ('3106', '赵明阳', '初级', '1500', '地理系'); insert into teacher

values ('7108', '张丽', '高级', '3500', '生物系'); insert into teacher

values ('9103', '王彬', '高级', '3500', '计算机系'); insert into teacher

values ('7101', '王力号', '初级', '1800', '生物系')

6、将所有学生年龄增加1岁。

Update(更新)stu(表名)

set age =age+1;

7、删除张小红教师的记录。

delete from teacher

where tname='张小红';

8、将所有职工工资增加100;

update teacher

set salary =salary+100;

9、使用SQL命令删除teacher中编号为9103的职工信息。

delete from teacher

where tno=9103;

10、删除所有工资收入大于3000的员工信息

delete from teacher

where salary>3000;

12、假设有另一个空表teacher2,结构和teacher表相同,使用insert into 语句将teacher表中数据添加到teacher2中。

insert into teacher2 select * from teacher;

相关文档
最新文档