JAVA学习笔记 MySQL2 - 表相关

  1. 创建表
  2. 查询所有表
  3. 查询表信息
  4. 查询表字段
  5. 删除表
  6. 修改表名
  7. 添加表字段
  8. 删除表字段
  9. 修改表字段
  10. 常见错误

1.创建表

  • 格式: create table 名字(字段1名 类型,字段2名 类型,…)charset=utf8/gbk;
create table person(name varchar(50),age int)charset=utf8;
create table student(name varchar(50),chinese int,math int,english int);

2.查询所有表

  • 格式: show tables;
show tables;

3.查询表信息

  • 格式: show create table 表名;
show create table person;

4.查询表字段

  • 格式: desc 表名;
 desc student;

5.删除表

  • 格式; drop table 表名;
drop table student;

 

6.修改表名

  • 格式: rename table 原名 to 新名;
rename table person to per; 

7.添加表字段

  • 最后面添加格式: alter table emp add 字段名 类型;
  • 最前面添加格式: alter table emp add 字段名 类型 first;
  • 某字段后面添加格式: alter table emp add 字段名 类型 after 字段名;
alter table emp add age int;
alter table emp add id int first;
alter table emp add gender varchar(10) after name;

8.删除表字段

  • 格式: alter table 表名 drop 字段名;
alter table emp drop gender;
alter table emp drop id;

9.修改表字段

  • 格式: alter table 表名 change 原名 新名 新类型;
alter table emp change age gender varchar(10);

常见错误:

ERROR 1046 (3D000): No database selected------没有选择数据库。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马里亚纳景川

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值