SQL语句应用
DDL:
操作数据库:
增加:
create databse [if not exists] 数据库名 [charset '码表名'];
删除:
drop database 数据库名;
修改:
alter database 数据库名 charset '码表名';
查看:
show databases;
show create database 数据库名;
select database();
操作数据表:
增加:
create table [if not exists] 数据表名(
列名 数据类型 [约束],
列名 数据类型 [约束],
...
列名 数据类型 [约束]
);
删除:
drop table 数据表名;
修改:
alter table 旧表名 rename 新表名;
rename table 旧表名 to 新表名;
查看:
show tables; # 查看(当前数据库中)所有的数据表.
desc 数据表名;
show create table 数据表名;
操作数据字段:
增加:
alter table 数据表名 add 新列名 数据类型 [约束];
删除:
alter table 数据表名 drop 旧列名;
修改:
alter table 数据表名 modify 旧列名 数据类型 [约束名];
alter table 数据表名 change 旧列名 新列名 数据类型 [约束名];
查看:
desc 数据表名;