增删查改之数据库,数据表,表字段

数据库的增删查改

create database `数据库名称` default charset utf8;
drop database `数据库名称`;
show create database `数据库名称`;
show tables from `数据库名称`;
alter database `数据库名称` charset utf8;

数据表的增删查改

create table `数据表名称`(
    `字段名称` 类型长度 not null auto_increment,
    `字段名称` 同上,
)engine innodb default charset utf8;
drop table `数据表名称`;
show create table `数据表名称`;
desc `数据表名称`;
alter table `数据表名称` engine innodb;
alter table `数据表名称` charset uft8;
alter table `数据表旧名称` rename to `数据表新名称`;
rename table `数据表旧名称` to `数据表新名称`;

数据表字段增删查改

alter table `数据表名称` add column (`字段名称`类型和长度, ...);
alter table `数据表名称`add primary key (`字段名称`);
alter table `数据表名称` add foreign key (`外键字段名称`) references `引用表名称` (`引用主键名称`);
alter table `数据表名称` drop `字段名称`;
alter table `数据表名称` drop primary key;
alter table `数据表名称` drop foreign key (`外键字段名称`);
desc `数据表名称`;
alter table `数据表名称` change `字段旧名称` `字段新名称`类型和长度;
alter table `数据表名称` modify `字段名称`类型和长度;

猜你喜欢

转载自www.cnblogs.com/zxcv123/p/11900348.html
今日推荐