实验4.2-3

该文描述了一系列的MySQL数据库操作,包括创建storeexpm和stuexpm两个数据库,然后在每个数据库中创建Employee和StudentInfo表,对表结构进行修改如添加、更改和删除字段,设置默认值,以及重命名和删除表。实验涉及了数据库设计和管理的基本概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实验4.2

mysql> create DATABASE storeexpm;

mysql> use storeexpm;

mysql> create table Employee

-> (

-> EmplID varchar(4) not null primary key,

-> EmplName varchar(8) not null,

-> Sex varchar(2) not null default '男',

-> Birthday date not null,

-> Address varchar(20) null,

-> Wages decimal(8,2) not null,

-> DeptID varchar(4) null

-> );

mysql> create table Department

-> (

-> DeptID varchar(4) not null primary key,

-> DeptName varchar(20) not null

-> );

mysql> create table Employee1 like Employee;

mysql> alter table Employee

-> add column Eno int not null unique auto_increment first;

mysql> alter table Employee1

-> change column Sex Gender char(2) null default '女';

mysql> alter table Employee1

-> change column Address Telephone char(20) null;

mysql> alter table Employee1

-> alter column Gender set default '男';

mysql> alter table Employee1

-> modify column Wages float after EmplName;

mysql> alter table Employee

-> drop column Eno;

mysql> alter table Employee1

-> rename to Employee2;

mysql> drop table Employee2;

实验4.3

mysql> create database stuexpm;

mysql> use stuexpm;

mysql> create table StudentInfo

-> (

-> StudentID varchar(6) not null primary key,

-> Name varchar(8) not null,

-> Sex varchar(2) not null default '男',

-> Birthday date not null,

-> Speciality varchar(12) null,

-> Address varchar(20) null

-> );

mysql> create table StudentInfo1 like StudentInfo;

mysql> alter table StudentInfo

-> add column StuNo int not null unique auto_increment first;

mysql> alter table StudentInfo1

-> change column Address City char(20) null default '北京';

mysql> alter table StudentInfo1

-> change column Speciality School char(20) null default '计算机学院';

mysql> alter table StudentInfo1

-> alter column City set default '上海';

mysql> alter table StudentInfo1

-> modify column City varchar(20) after Name;

mysql> alter table StudentInfo

-> drop column StuNo;

mysql> alter table StudentInfo1

-> rename to StudentInfo2;

mysql> drop table StudentInfo2;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值