1、數據庫操作
#創建數據庫
create database 數據庫名 charset=utf8;
#刪除數據庫
drop database 數據庫名;
#切換數據庫/使用數據庫
use 數據庫名;
#查看當前選擇的數據庫
select database();
#查看所有數據庫
show databases;
2、表操作
#查看當前數據庫中所有表
show tables;
#創建表
auto_increment表示自動增長
create table 表名(列及類型);
如:
create table students(
id int auto_increment primary key,
name varchar(10) not null,
birthday datetime,
gender bit default 1,
isDelete bit default 0
);
#修改表
alter table 表名 add|change|drop 列名 類型;
如:
#增加列
alter table students add hometown varchar(20) not null;
#修改列名
alter table students change hometown tel int(11) not null;
#刪除列
alter table students drop tel;