SQL基础DDL语句

1,创建数据库test1

create database test1;

2,选择数据库test1

use test 1

3,查看test1数据库中创建的所有数据表

show tables;

4,删除test1数据库

drop database test1;

5,创建一个名称为 emp 的表。表中包括 3 个字段,ename(姓名),hiredate(雇用日期)、
sal(薪水),字段类型分别为 varchar(10)、date、int(2)

create table emp(
ename varchar(10),
hiredate date,
sal decimal(10,2),
deptno int(2)
);

6,查看emp表的定义

desc emp;

7,查看创建表的sql语句

show create table emp;

8,删除数据库emp表

dorp table emp;

9,修改表emp的ename字段定义,将varchar(10)改为varchar(20)

alter table emp modify eanme varchar(20)

10, 表 emp 上新增加字段 age,类型为 int(3)

alter table emp add column age int(3);

11, 将字段age删除掉

alter table emp drop column age;

12, 将 age 改名为 age1,同时修改字段类型为 int(4)

alter table emp change age age1 int(4);

13,将新增的字段 birth date 加在 ename 之后:

alter table emp add birth date after ename;

14, 修改字段 age,将它放在最前面:

alter table emp modify age int(3) first;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值