数据库及表的创建与操作

  1. 使用SQL语句熟练地创建、修改和删除MySQL数据库;
  2. 理解和掌握数据定义(DDL)语言,能够熟练地使用DDL语句创建、修改和删除基本表并实施完整性定义与维护;

 

在MySQL服务器中,创建数据库company,在company数据库中创建两个数据表offices和employees,按照操作过程完成对数据表的基本操作。

  1. 创建数据库company
  2. 创建表offices
  3. 创建表employees
  4. 将employees的mobile字段修改到officeCode的后面
  5. 将employees的birth字段改名为employee_birth
  6. 修改employees的sex字段,数据类型为CHAR(1),非空约束
  7. 删除employees的字段note
  8. 在employees表中增加字段名favorite_activity,数据类型为VARCHAR(100)

 

步骤(算法、程序)、数据记录与处理、结果分析等

(1)create database if not exists company default charset = utf8 collate = utf8_general_ci;

use company;

(2)create table if not exists offices(

officeCode int(10) auto_increment primary key,

city varchar(50) not null,

address varchar(50),

country varchar(50) not null,

poatalCode varchar(15) unique);

(3)create table employees

(

 employeenumber int(11) not null primary key auto_increment,

 lastname varchar(50) not null,

 firstname varchar(50) not null,

 mobile varchar(25) not null,

 officecode int(10) not null,

 jobtitle varchar(50) not null,

 birth datetime,

 note varchar(255),

 sex varchar(5),

 constraint office_fk foreign key (officecode) references offices(officecode)

);

(4)alter table employees modify mobile varchar(25) after officeCode;

(5) alter table employees change birth employees_birth datetime;

(6) alter table employees modify sex char(1) not null;

(7) alter table employees drop note;

(8)alter table employees add favorite_activity varchar(100);

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值