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

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

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

表1   Employees表结构

列名

数据类型

长度

是否允许为空

说明

EmployeeID

char

扫描二维码关注公众号,回复: 4610329 查看本文章

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;

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

 

Show create database  yggl;

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

Set  character_setdatabase=’utf-8’;

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

);

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

 

Desc  employees;

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

Show  create   table  employees;

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

 

Create table departments

(departments char(3)  not null  primary  key,

Departmentname  char(20)  not null,

Note text(16) null

);

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

Create table salary

(employeeid char(6) not null primary key,

Income  float(8)  not null,

Outcome  float(8)  not null

);

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;

 

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

Create table  salary2 like salary;

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

Alter  table  salary1  add  column  salaries  float;

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

Alter  table  salary1  alter  income  set  default  2000;

Alter  table  salary  change  salaries  truecome  float;

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

Alter  table  salary  drop  column  truecome;

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

Alter  table  salary1  rename  to  money;

15、   删除表Salary1。

Drop  table  money;

猜你喜欢

转载自www.cnblogs.com/lvwuwa/p/10162768.html