MySQL语句大全
第一部分:对数据库表的操作
1、创建数据库
create database [if not exists] 数据库名;
2、使用数据库
use 数据库名;
3、查看所有的库
show databases;
3、查看当前库中所有的表
show tables;
4、删除数据库
drop database [if exists] 数据库名;
5、alter更新
- (添加字段)
alter table 表名 add 字段名 属性值; - (删除)
alter table 表名 drop 字段名; - (modify修改)
alter table 表名 modify 字段名 属性值; - (change修改)
alter table 表名 add 旧字段名 新字段名 属性值;
change用来字段重命名,不能修改字段类型和约束;
modify不用来字段重命名,只能修改字段类型和约束;
第二部分:对数据库表中数据的操作
1、创建数据库
create table tabname(
col1 type1 [not null] [auto_increment][primary key],
col2 type2 [not null],
…);
根据已有的表创建新表:
A:create table t_new like t_old;
B:create table t_new as select * from t_old;
2、删除表
drop table 表名;
3、更新数据表中的数据
update 表名 set 字段名=新值,字段名2=新值·····where 字段名=值;
····················持续更新中 ·····························