我的作业呢

本文介绍了如何在MySQL中创建'company'数据库,包括'offices'和'employees'表的设计,字段调整,表结构查看,以及后续的表操作如重命名、删除等。涉及SQL命令和数据库结构管理的关键步骤。
摘要由CSDN通过智能技术生成

创建数据库company,在库中创建两个表offices和employees表
create database company;
use company;
create table offices(
officeCode int(10) PRIMARY KEY NOT NULL UNIQUE,
city VARCHAR(50) NOT NULL,
address VARCHAR(50),
country VARCHAR(50) NOT NULL,
postalCode VARCHAR(15) UNIQUE
);
create table employees(
employeeNumber int(11) PRIMARY KEY not null unique auto_increment,
lastName VARCHAR(50) not null,
firstName VARCHAR(50) not null,
mobile VARCHAR(25) unique,
officeCode int(10) not null,
jobTitle varchar(50) not null,
birth datetime not null,
note varchar(255),
sex varchar(5)
);
查看该库下几个表以及查看两张表结构
show tables;
desc employees;
desc offices;
将表employees的mobile字段修改到officeCode字段后面
alter table employees modify mobile varchar(25) after officeCode;
将表employees的birth字段改名为employee_birth
alter table employees change birth employee_birth datetime;
修改sex字段,数据类型为CHAR(1),非空约束
alter table employees modify sex char(1) not null;
删除字段note
alter table employees drop note;
增加字段名favoriate_activity,数据类型为VARCHAR(100)
alter table employees add favority_activity varchar(100);
删除表offices
drop table offices;
将表employees名称修改为employees_info
alter table employees rename to employees_info;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值