-
对数据库常用操作
-
对表结构常用操作
-
修改表结构
1. 对数据库常用操作
-
查看所有的数据库
show databases;
-
创建数据库
create database if not exists mydatabase1;
-
切换需要执行的数据库
use mydatabase1;
-
删除数据库
drop database if exists mydatabase1;
2.对表结构的常用操作
-
创建表
create table if not exists student(
stuid int,
name varchar(20),
gender varchar(20),
birth date,
age int,
score double
);
注意:创建表后要加分号,最后一列数据后不加逗号,执行前需要切换到要执行的数据库。
-
其他操作
-
查看当前所有的表
show tables;
-
查看某个表的创建语句
show create table student;
-
查看表结构
desc student;
-
删除表
drop table if exists student;
-
-
修改表结构
-
添加列
alter table student add `address` varchar(20);
-
修改列名和类型
alter table student change `address` stuaddress varchar(30);
-
删除列
alter table student drop `stuaddress`;
-
修改表名
rename table student to studentinformation;
-