0
点赞
收藏
分享

微信扫一扫

JAVA学习笔记 MySQL2 - 表相关

爱读书的歌者 2022-03-12 阅读 64

目录

表相关操作


  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 条评论