![](https://img-blog.csdnimg.cn/6012bc67024b41dc8a5299bba69e6b97.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYWlnby0yMDIx,size_20,color_FFFFFF,t_70,g_se,x_16)
编写以下语句
1.创建dept表
2.创建emp表
3.将列Last_name的长度增加到50
4.根据表emp创建employees2
5.删除表employees2
6.在表dept和emp中添加新列test_column,并检查所作的操作
7.在表dept和emp中将列test_column删除
8.直接删除表emp中的列 dept_id
答:
1.
create table dept(
id int not null,
name varchar(25) not null,
location varchar(25)
)
![](https://img-blog.csdnimg.cn/557c31ae8ca44a63b4c27dd11abc9a23.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYWlnby0yMDIx,size_13,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/c065f562622d4fc19981774255fd21e1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYWlnby0yMDIx,size_20,color_FFFFFF,t_70,g_se,x_16)
2.
create table emp(
id int,
First_name varchar(25),
Last_name varchar(25),
dept_id int
)
![](https://img-blog.csdnimg.cn/1dcdbbaf3bc64c579aa1fe3a2967fc67.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYWlnby0yMDIx,size_20,color_FFFFFF,t_70,g_se,x_16)
![](https://img-blog.csdnimg.cn/04af729a8aa34e73856f5ee9f3290717.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAYWlnby0yMDIx,size_20,color_FFFFFF,t_70,g_se,x_16)
3.
drop table emp;
create table emp(
id int,
First_name varchar(25),
Last_name varchar(25),
dept_id int
);
alter table emp modify column last_name varchar(50);
4.
drop table emp;
create table emp(
id int,
First_name varchar(25),
Last_name varchar(25),
dept_id int
);
create table employees2
select * from emp
5.
drop table employees2;
6.
alter table dept add test_column varchar(255);
alter table emp add test_column varchar(255);
7.
alter table dept drop test_column;
alter table emp drop test_column;
8.
alter table emp drop column dept_id;