实验三 mysql数据库与表的创建_实验二 数据库和表的创建与管理

实验二 数据库和表的创建与管理

创建用于企业管理的员工管理数据库,数据库名为YGGL中,YGGL数据库中包括三个表:Employees(员工信息表)、Departments(部门信息表)、Salary(员工薪水情况表)。各表的结构如下表:

表1   Employees表结构

列名

数据类型

长度

是否允许为空

说明

EmployeeID

char

6

not null

员工编号,主键

Name

char

10

not null

姓名

Education

char

4

not null

学历

Birthday

date

not null

出生日期

Sex

char

2

not null

性别

Workyear

tinyint

1

null

工作年限

Address

varchar

20

null

地址

Phonenumber

char

12

null

电话号码

DepartmentID

char

3

null

员工部门号,外键

表2  Departments表结构

列名

数据类型

长度

是否允许为空

说明

DepartmentID

char

3

not null

部门编号,主键

Departmentname

char

20

not null

部门名

Note

text

16

null

备注

表 3   Salary表结构

列名

数据类型

长度

是否允许为空

说明

EmployeeID

char

6

not null

员工编号,主键

Income

float

8

not null

收入

Outcome

float

8

not null

支出

1、  创建数据库YGGL;

Create database yggl;

e3919e0c5b3e8602a4e7390ff9ec6c59.png

2、  使用“show create database数据库名”查看数据库YGGL的字符集;

Show create database  yggl;

2e63016a0fa40f68f863aaf6ceede236.png

3、  修改YGGL数据库的默认字符集为utf8;

Set  character_setdatabase=’utf-8’;

b6727cac7e7a87a7a57ceb71990fc776.png

4、  在YGGL数据库中创建表Employees;

Use yggl;

Create table employees

(employeeid char(6)  not null primary key,

Name char(10) not null,

Education char(4) not null,

Birthday date not null,

Sex char(2)  not null,

Workyear  tinyint(1)  null,

Address  varchar(20) null,

Phonenumber char(12) null,

Departmentid  char(3)  null

);

da5edc5a06e9d8e62b89e3cf955a91a8.png

5、  使用“desc(describe的缩写)表名”查看表信息;

Desc  employees;

045c130e535e63ec7c56b414ecb2b1d2.png

6、  使用“show create table 表名”查看创建表命令的详细信息;

Show  create   table  employees;

8b85d54c6bc2ac699cadcf60ab4ab394.png

7、  在YGGL数据库中创建表Departments;

Create table departments

(departments char(3)  not null  primary  key,

Departmentname  char(20)  not null,

Note text(16) null

);

52cd0956987156fd08c717674d8e6959.png

8、  在YGGL数据库中创建表Salary;

Create table salary

(employeeid char(6) not null primary key,

Income  float(8)  not null,

Outcome  float(8)  not null

);

d74213b5b085b61445a145f0ccd82907.png

9、  在YGGL数据库中创建表Salary1,要求使用数据库存储引擎为MyISAM,表结构与Salary相同;

Create table salary

(employeeid char(6) not null primary key,

Income  float(8)  not null,

Outcome  float(8)  not null

)engine=MyISAM;

39abc7ec9e7ae439036c2bb0e7455fd0.png

10、  复制一个表Salary2,要求表结构与Salary表相同。

Create table  salary2 like salary;

f8984032bec335f3b5ed237c63d826b5.png

11、   在Salary1表中增加列:Salaries   float;

Alter  table  salary1  add  column  salaries  float;

c41b7560c2d353ff322e38a972f641f6.png

12、   修改Salary1表中Income的默认值为2000,修改Salary表列名Salaries为“实发工资”;

Alter  table  salary1  alter  income  set  default  2000;

2eb68baaa69494dc21fa186a4e98459e.png

Alter  table  salary  change  salaries  truecome  float;

59a12a4dddf9a1b83cc8fe1a9527cf07.png

13、   删除列“实发工资”;

Alter  table  salary  drop  column  truecome;

7b085386090d8b2c28c1d9026e6a82ea.png

14、   修改表名Salary1为“薪水表”

Alter  table  salary1  rename  to  money;

571aa32020d384bc196821dfeb3b7a44.png

15、   删除表Salary1。

Drop  table  money;

5b37126e5477fb814682a33411b223bc.png

  • 9
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值