- 创建数据库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;
【无标题】
最新推荐文章于 2024-03-13 16:47:57 发布